如果是yes=(dialogResult == JOptionPane.YE S_OPTION),我需要包含一个重新启动程序的循环,如果是,它会将新项目添加到订单列表中。
(真的不知道怎么弄……)
导入 javax.swing.JOptionPane;
公共类菜单2 {
public static void main(String[] args, Object start_ex) {
String entree;
int e;
String meat;
int m;
String beans;
int b;
//String salsa;
//int s;
//String guacamole;
//int g;
//String rice;
//int r;
String entreeName = "";
String meatName = "";
String beansName = "";
JOptionPane.showMessageDialog(null, "Welcome to Chipotle Kendall");
// ask user for input
entree= JOptionPane.showInputDialog("Choice of entree 1:Rice Bowl/ 2:Burrito (number)?");
meat= JOptionPane.showInputDialog("Choice of meat 1:Steak/ 2:Chicken/ 3:Veggie (number)?");
beans= JOptionPane.showInputDialog("Choice of beans 1:black/ 2:pinto/ 3:none (number)?");
// convert variable in to inputs
e = Integer.parseInt(entree);
m = Integer.parseInt(meat);
b = Integer.parseInt(beans);
double entreeprice = 3;
double meatprice = 1;
double beansprice = 3;
// price
if (m==1)
{
meatprice= 8.0;
}
else if (m==2)
{
meatprice= 7;
}
else if (m==3)
{
meatprice=5;
}
double price= entreeprice + meatprice + beansprice;
double pricePlusMATaxes= price + (price * 0.06);
double pricePlusCATaxes=price + (price * 0.06) + (price * 0.05);
// choice of entree
if (e==1)
{
entreeName = "Ricebowl";
}
else if (e==2)
{
entreeName = "Burrito";
}
// choice of meat
if (m==1)
{
meatName = "Steak";
}
else if (m==2)
{
meatName = "Chiken";
}
else if (m==3)
{
meatName = "Veggie";
}
// choice of beans
if (b==1)
{
beansName = "black";
}
else if (b==2)
{
beansName = "pinto";
}
else if (b==3)
{
beansName = "none";
}
Object[] options = {"Yes",
"No",
"Cancel Order"};
JOptionPane.showOptionDialog(null, "Order list is: " + entreeName + "\nwith " + meatName + "\nwith " + beansName + "beans",
"Order List Confirmation",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[2]);
int dialogResult = JOptionPane.showOptionDialog(null, null,
"Do you want to add another Item",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[2]);
if (dialogResult == JOptionPane.NO_OPTION)
{
System.out.println("Order List: " + entreeName + " with " + meatName + " with " + beansName + " beans ");
System.out.println("Subotal: " + price);
System.out.println("MA sales tax: " + pricePlusMATaxes);
System.out.println("Cambridge sales tax: " + pricePlusCATaxes);
}
}
}