I have a project that asks me to make a pizza ordering system, and everything is working fine except for one or two parts.
The first thing wrong is that within the second case I have this part that syas I need to ask if they would like to order more pizzas and if they input y or Y then it needs to loop back to asking them what size they would like, but if they input n or N it goes back to the main menue. Both yes and no take them back to main menu?
And the other part that is broken is that it says I haven't initialized currentTotal, which I cant really initailize because I wont know how many of what someone will input.
The only other thing that might not work is the forth case, because it needs to wipe out everything and jus start the program over? I just made it so that toalExpence would equal 0 but I think thats wrong.
It is due tonight by 11:59 EasternTime, but I could really use any help at all even if it doesn't completely fix it. Thank you!
This question is not just asking how to compare strings, infact I didn't even ask that, so it is not a duplicate.
import java.util.Scanner;
public class orderPizza{
public static void main(String[] args){
Scanner kb = new Scanner(System.in);
double LARGE_PIZZA_PRICE = 16.99;
double MEDIUM_PIZZA_PRICE = 14.99;
double SMALL_PIZZA_PRICE = 12.99;
double totalExpense = 0.00;
double temp;
double currentTotal = temp;
System.out.println("Welcome to the Pizza Ordering System.");
System.out.println("1.List prices");
System.out.println("2.Place order");
System.out.println("3.Display total amount to pay");
System.out.println("4.Cancel the current order");
System.out.println("5.Exit program");
boolean quit = false;
do {
System.out.println(" Please input the number of your choice to continue:");
int choice = kb.nextInt();
switch (choice) {
case 1:
System.out.println("You've chosen List prices");
System.out.println("Large pizza: $"+LARGE_PIZZA_PRICE);
System.out.println("Medium pizza: $"+MEDIUM_PIZZA_PRICE);
System.out.println("Small pizza: $"+SMALL_PIZZA_PRICE);
break;
case 2:
System.out.println("You've chosen Place order");
System.out.println("Please choose the size of pizza (1. Large; 2. Medium; 3. Small;)");
int size = kb.nextInt();
System.out.println("Please input the number of pizzas you would like to order (1 - 10)");
int orderAmount = kb.nextInt();
//calculating prices
double subtotal = size * orderAmount;
if(size == 1){
subtotal = LARGE_PIZZA_PRICE * orderAmount;
temp = totalExpense + subtotal;
}
else if(size == 2){
subtotal = MEDIUM_PIZZA_PRICE * orderAmount;
temp = totalExpense + subtotal;
}
else if(size == 3){
subtotal = SMALL_PIZZA_PRICE * orderAmount;
temp = totalExpense + subtotal;
}
else if (size > 3){
System.out.println("Invalide number");
}
System.out.println("Do you want to order more? (y/n)");
kb.nextLine();
String yesNo = kb.nextLine();
if(yesNo == "y" || yesNo == "Y"){
continue;
}
else if(yesNo == "n" || yesNo == "N"){
break;
}
break;
case 3:
System.out.println("You've chosen Display total amount to pay");
System.out.println("Your current total is: ");
break;
case 4:
System.out.println("You've chosen Cancle the current order");
totalExpense = 0;
System.out.println("Your order is canceled and your total expense is 0 now.");
break;
case 5:
quit = true;
break;
default:
System.out.println("Invalid choice.");
}
} while (!quit);
System.out.println("Bye-bye!");
}
}