Quote (axid3nt @ Jan 25 2015 09:35pm)
I will try this, and I think I understand what you're articulating.. I'm pressed for time, having to get up in 8 hours for work so I'm going to keep it for now and finish.
I am stuck in the part: While-------code------ and then I get to my else(the one that represents anything deviating from normal input) and my idea would be first to set a counter.. and use the i++ method to log the times/counts the user has reacher this output, set it i<=3 allowing the user to try again, and then i==3 break at that point... I have the while setup but unsure of the code needed for this.. I'll be digging through my book.
something like this?
Code
//Prompts the user for a double. if the user fails to supply a correct double after 3 attempts, the program exits
public double readDouble(Scanner console)
{
boolean correct = false;
int attempts = 0;
double number = 0.0;
do
{
try
{
System.out.println("Please enter a double: ");
String in = console.nextLine();
number = Double.parseDouble(in);
correct = true;
}catch(NumberFormatException nfe)
{
System.out.println("ERROR: You did not enter a double");
correct = false;
}
attempts++;
}while(!correct && attempts < 3);
if(attempts == 3)
System.exit(1); //exit with 1 to indicate there was an error
return number;
}