Professional Documents
Culture Documents
Scanner Menu: "Welcome /n1. Burger ($2.00) /n2. Fries ($1.50) /n3. Soda ($1.00) /n4. Done"
Scanner Menu: "Welcome /n1. Burger ($2.00) /n2. Fries ($1.50) /n3. Soda ($1.00) /n4. Done"
Scanner;
3 Answers
up vote1down vote
You are resetting the double runningTotal=0; in the while loop. Also the price returned by
the itemPrice needs to be added into the runningTotalvariable;
This is how your main method shoul
public static void main(String[] args) {
int menuOption;
int foodItem = 0;
input = new Scanner(System.in);
double runningTotal=0;
do{
menu();
menuOption = input.nextInt();
switch(menuOption){
case 1:
foodItem = 1;
runningTotal += itemPrice(foodItem);
break;
case 2:
foodItem = 2;
runningTotal += itemPrice(foodItem);
break;
case 3:
foodItem = 3;
runningTotal += itemPrice(foodItem);
break;
case 4:
done(runningTotal);
break;
default:
System.out.println("Invalid option.");
}
} while(ordering);
System.out.println("Total amount: " + runningTotal);
}
Output:
Welcome
1. Burger ($2.00)
2. Fries ($1.50)
3. Soda ($1.00)
4. Done
1
You've ordered a burger
Enter quantity
2
Subtotal: 4.0
Welcome
1. Burger ($2.00)
2. Fries ($1.50)
3. Soda ($1.00)
4. Done
2
You've ordered fries
Enter quantity
1
Subtotal: 1.5
Welcome
1. Burger ($2.00)
2. Fries ($1.50)
3. Soda ($1.00)
4. Done
4
3.5
Enjoy your meal
Total amount: 3.5
shar