I use this method to check the values from the scanner. My do-while loop prints an error message and then resets to the beginning of the scanner after an invalid value is detected. But it also resets when I've used good values, without the error message.
I've been googling up a storm, but I can't see what I'm doing wrong. Any help would be greatly appreciated.
public boolean invalidInput() {
if (!(myHeight > 36 && myHeight < 100 ||
myWeight > 50 && myWeight < 500 ||
myAge > 12 && myAge < 100) )
System.out.println ("An unrealistic value has been entered." +
"\n" + "Please enter your information again." + "\n");
return true;
do{
System.out.print("Enter height in inches: ");
height = in.nextDouble();
bmi.setHeight(height);
System.out.print("Enter weight in pounds: ");
weight = in.nextDouble();
bmi.setWeight(weight);
System.out.print("Enter age in years: ");
age = in.nextInt();
bmi.setAge(age);
} while (bmi.invalidInput() == true);