我有一个项目要求我制作披萨订购系统,除了一两个部分外,一切正常。
第一个错误的是,在第二种情况下,我有这个部分,我需要询问他们是否想要订购更多的比萨饼,如果他们输入y或Y,那么它需要循环回来询问他们的大小我想,但如果他们输入n或N,它会回到主要的菜单。是和否都将它们带回主菜单?
另一个被打破的部分是它说我没有初始化currentTotal,我不能真正启动,因为我不知道有多少人会输入。
唯一可能不起作用的是第四种情况,因为它需要消除所有内容并且jus启动程序?我刚刚做到这一点,以便toalExpence等于0,但我认为这是错误的。
它将于今晚11:59东部时间到期,但即使它没有完全解决它,我也可以使用任何帮助。 谢谢!
这个问题不只是询问如何比较字符串,事实上我甚至没有问过,所以它不是重复的。
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!");
}
}