1

如果是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); 
        }




 }
}
4

1 回答 1

0

The method signature of your main() method must be the following:

public static void main(String[] args) {

This is just what all main methods have to be declared as.

Rather than restarting your program by calling your main() method yourself, if that is what you are proposing, I would have a loop. I see that you know that because your question has tags about "loops".

Here is an example. If I can help you further, you are welcome to send me an email at: kaydell@yahoo.com or chat with me with Yahoo! Messenger at my ID of "kaydell".

import javax.swing.JOptionPane;

public class SellMeal {

    public static void takeOrders() {
        boolean done = false;
        do {
            // get the choice of entrees
            String entreeCode = JOptionPane.showInputDialog("Please Select Your Choice of Entrees, 1) Chicken Delight, 2) Roast Beef Meal, 3) Fish and Chips.", "1");
            // if the user cancels, then break out of the loop
            // you have to check for null anyways so that the program doesn't crash and exit with a NullPointerException
            if (entreeCode == null) {
                // the user canceled, set done to true to exit this loop
                done = true;
            } else {
                // the user chose an entree code
                System.out.println("Entre Code: " + entreeCode);
                String message = "You chose entree code: " + entreeCode + " Do you want to choose another entree.";
                int buttonClicked = JOptionPane.showConfirmDialog(null, message, "", JOptionPane.YES_NO_OPTION);
                done = (buttonClicked == JOptionPane.NO_OPTION);
            }
        } while (!done);
    }

    public static void main(String[] args) {
        takeOrders();
    }

}
于 2013-09-13T18:23:13.433 回答