I have this code, its supposed to ask the user for input and stop when the user inputs false. If its not, it is supposed to do different things based on what they enter.
//ask the user if they want to view the average
System.out.println("Do you want to view the average of your data? please answer with true or false?");
currentAnswer = scan.nextBoolean();
if(currentAnswer){
System.out.println("If yes, please type in one of the following(type false to exit)\n calories - protein - weight - rating");
}
String option;
/***
This is where the problem is. The code prints "Please type in one of the following....." twice instead of once, otherwise it works as intended.
*/
while(currentAnswer){
option = scan.nextLine();
switch (option) {
case "calories": System.out.println(dataAverage("calories"));
break;
case "protein": System.out.println(dataAverage("protein"));
break;
case "rating": System.out.println(dataAverage("rating"));
break;
case "weight": System.out.println(dataAverage("weight"));
break;
case "false": currentAnswer = false;
break;
}
System.out.println(" Please type in one of the following(type false to exit)\n calories - protein - weight - rating");
}
I tried a do while loop, but the problem is still there. Any ideas?