无法访问的语句切换

时间:2013-03-20 14:55:18

标签: java

我有一个无效的POS程序说 开关(食物)

import javax.swing.*;
import java.awt.*;

public class sari{
public static void One()
{
int choice=0,food=0,c=0,con,x=1,y=1,z=1,q=1,trans=0,price=0 ,qty,gtotal=0,ptotal=0,pay,change,total=0,ord;
String order="",bibilhin="",transaction="",A;




                   ImageIcon welcome = new ImageIcon("welcome.jpg");
            ImageIcon chip = new ImageIcon("chip.jpg");
            ImageIcon rc = new ImageIcon("rc.jpg");
            ImageIcon stick = new ImageIcon("stick.jpg");
            ImageIcon pancit = new ImageIcon("pancit.jpg");
            ImageIcon jampong = new ImageIcon("jampong.jpg");
            ImageIcon chups = new ImageIcon("chups.jpg");
            ImageIcon egg = new ImageIcon("egg.jpg");
            A=JOptionPane.showInputDialog("Enter your name:");              ImageIcon hansel = new ImageIcon("hansel.jpg");

JOptionPane.showMessageDialog(null,"Sir/Ma`am \n "+A+"\n Welcome\n to Mang Inasal\n Please Choose The\n product you want to buy","Welcome" ,JOptionPane.PLAIN_MESSAGE,welcome);
    while(x==1) 
            {
            c=Integer.parseInt(JOptionPane.showInputDialog("  Categories" + "\n" +"[1] Drinks" + "\n" + "[2] Foods"));



    if(c==1)
        {choice=Integer.parseInt(JOptionPane.showInputDialog("DRINKS" +"\n"
                        + "[1] Lemonade" + "\n"
                        + "[2] Coca Cola" + "\n"
                        + "[3] Sprite" + "\n"
                        + "[4] Mountain Dew" + "\n"
                        + "[5] Pepsi" + "\n"
                        + "[6] Cofee" +"\n"
                        + "[7] Hot Choco" +  "\n"
                        + "[8] Nestie Iced Tea" +"\n"
                        + "[9] Exit" +"\n"
                        + "Enter Your Choice:"));
    if(c==2)
        food=Integer.parseInt(JOptionPane.showInputDialog("Food" +"\n"
                        + "[1] L" + "\n"
                        + "[2] Coca Cola" + "\n"
                        + "[3] Sprite" + "\n"
                        + "[4] Mountain Dew" + "\n"
                        + "[5] Pepsi" + "\n"
                        + "[6] Cofee" +"\n"
                        + "[7] Hot Choco" +  "\n"
                        + "[8] Nestie Iced Tea" +"\n"
                        + "[9] Exit" +"\n"
                        + "Enter Your Choice:"));   

    }

        switch(choice)
            {
                case 1:
                    price = 20;
                    bibilhin= " Lemonade";
                    break;
                case 2:
                    price = 20;
                    bibilhin= "Coca Cola ";
                    break;
                case 3:
                    price =820;
                    bibilhin = "Sprite";
                    break;
                case 4:
                    price =205;
                    bibilhin= "Mountain dew";
                    break;
                case 5:
                    price =20;
                    bibilhin= "Pepsi";
                    break;
                case 6:
                    price =25;
                    bibilhin= "Cofee ";
                    break;
                case 7:
                    price =25;
                    bibilhin= "Hot Choco";
                    break;
                case 8:
                    price = 20;
                    bibilhin= "Nestie Ice tea";
                    break;
                case 9:
                    JOptionPane.showMessageDialog(null,transaction+"Total sales: " + gtotal,"Transactions",JOptionPane.INFORMATION_MESSAGE);
                    JOptionPane.showMessageDialog(null,"You are about to exit!","Exit",JOptionPane.WARNING_MESSAGE);
                    do{
                        con=Integer.parseInt(JOptionPane.showInputDialog("Are you sure you want to exit?\n[1] Yes\n[0] No"));
                        if(con==1)
                            System.exit(0);
                        else if(con==1)
                        {
                            JOptionPane.showMessageDialog(null,"THANK YOU!\nGood Bye!","Exit",JOptionPane.ERROR_MESSAGE);
                            break;

                        }
                        else
                        {
                            JOptionPane.showMessageDialog(null,"Invalid Choice!","Error",JOptionPane.ERROR_MESSAGE);
                            con=1;
                        }

                       }while(con==1);
                       continue;
                default:
                    JOptionPane.showMessageDialog(null,"Invalid Choice!","ERROR",JOptionPane.ERROR_MESSAGE);
}

            do{//do1

            qty = Integer.parseInt(JOptionPane.showInputDialog("Quantity:"));

            if (qty>0)
                break;
            else
            {
                JOptionPane.showMessageDialog(null,"Invalid Input!","Error",JOptionPane.ERROR_MESSAGE);
                continue;
            }
            }while(q==1);//end do1

            total = price * qty;
            ptotal = ptotal+total;
            order = order +bibilhin+"                 "+qty+"                  "+price+"="+total+"\n";

            do  {//do2
            con = Integer.parseInt(JOptionPane.showInputDialog("Continue?[1] yes [0] no"));
                    if(con==1)
                    {

                        break;
                    }
                    else if(con==0)
                    {

                        do{
pay = Integer.parseInt(JOptionPane.showInputDialog(order+"Total " +ptotal+"\nEnter Payment:"));
if(pay>=ptotal)
                                {

change = pay-ptotal;
JOptionPane.showMessageDialog(null,"  \t                    Mang Inasal"+
            "\n\t           14 T molina st purok 6-B "+
            "\n\t              Alabang Muntinlupa City  "+
            "\nOperator: Micko Mendoza"+
            "\n\t----------------------------------------------------------------"+
            "\n\n\t   "+order+"\nTotal "+ptotal+
"\nCash "+pay+
"\nChange "+change+
            "\n----------------------------------------------------------------"+
            "\n\n \t            Thanks For buying!!!!!"+
                            "\n\t  This Serve as an official reciept DTSN:41D983"+
            "\n     \t       For Delivery Dial (519-6936)"+
            "\n    \t               Feedbacks"+
            "\n  \t             micko.mendoza@yahoo.com"
);
                                    y=0;
                                    z=0;
                                    x=1;
                                    gtotal = gtotal+ptotal;
                                    trans++;
                                    order="";
                                    transaction = transaction+"Transaction "+ trans+ " "+ptotal+"\n";//No of transactions
                                    ptotal = 0;
                                    do{
                                        con=Integer.parseInt(JOptionPane.showInputDialog("Next Customer?\n[1] Yes\n[0] No"));
                                        if(con==1)
                                            break;
                                        else if(con==0)
                                        {
                                            JOptionPane.showMessageDialog(null,transaction+"Total sales: " + gtotal,"Transactions",JOptionPane.INFORMATION_MESSAGE);
                                            System.exit(0);
                                        }
                    else
                    {
                        JOptionPane.showMessageDialog(null,"Invalid Choice!","Error",JOptionPane.ERROR_MESSAGE);
                        continue;
                    }

                }while(con==1);
                                    break;
                                }
                            else
                                {
                                    JOptionPane.showMessageDialog(null,"Kulang pera mo");

                                    continue;
                                }
                            }while(z==1);//do3

                    }
                    else
                    {
                        JOptionPane.showMessageDialog(null,"Intiger lang pwede","Continue",JOptionPane.ERROR_MESSAGE);
                        y=1;
                        continue;
                    }
                }   while(y==1);//do2

                break;




        switch(food)
            {
                case 11:
                    price = 20;
                    bibilhin= " Lemonade";
                    break;
                case 12:
                    price = 20;
                    bibilhin= "Coca Cola ";
                    break;
                case 13:
                    price =820;
                    bibilhin = "Sprite";
                    break;
                case 14:
                    price =205;
                    bibilhin= "Mountain dew";
                    break;
                case 15:
                    price =20;
                    bibilhin= "Pepsi";
                    break;
                case 16:
                    price =25;
                    bibilhin= "Cofee ";
                    break;
                case 17:
                    price =25;
                    bibilhin= "Hot Choco";
                    break;
                case 18:
                    price = 20;
                    bibilhin= "Nestie Ice tea";
                    break;
                case 19:
                    JOptionPane.showMessageDialog(null,transaction+"Total sales: " + gtotal,"Transactions",JOptionPane.INFORMATION_MESSAGE);
                    JOptionPane.showMessageDialog(null,"You are about to exit!","Exit",JOptionPane.WARNING_MESSAGE);
                    do{
                        con=Integer.parseInt(JOptionPane.showInputDialog("Are you sure you want to exit?\n[1] Yes\n[0] No"));
                        if(con==1)
                            System.exit(0);
                        else if(con==1)
                        {
                            JOptionPane.showMessageDialog(null,"THANK YOU!\nGood Bye!","Exit",JOptionPane.ERROR_MESSAGE);
                            break;

                        }
                        else
                        {
                            JOptionPane.showMessageDialog(null,"Invalid Choice!","Error",JOptionPane.ERROR_MESSAGE);
                            con=1;
                        }

                       }while(con==1);
                       continue;
                default:
                    JOptionPane.showMessageDialog(null,"Invalid Choice!","ERROR",JOptionPane.ERROR_MESSAGE);
}

            do{//do1

            qty = Integer.parseInt(JOptionPane.showInputDialog("Quantity:"));

            if (qty>0)
                break;
            else
            {
                JOptionPane.showMessageDialog(null,"Invalid Input!","Error",JOptionPane.ERROR_MESSAGE);
                continue;
            }
            }while(q==1);//end do1

            total = price * qty;
            ptotal = ptotal+total;
            order = order +bibilhin+"                 "+qty+"                  "+price+"="+total+"\n";

            do  {//do2
            con = Integer.parseInt(JOptionPane.showInputDialog("Continue?[1] yes [0] no"));
                    if(con==1)
                    {

                        break;
                    }
                    else if(con==0)
                    {

                        do{
pay = Integer.parseInt(JOptionPane.showInputDialog(order+"Total " +ptotal+"\nEnter Payment:"));
if(pay>=ptotal)
                                {

change = pay-ptotal;
JOptionPane.showMessageDialog(null,"  \t                    Mang Inasal"+
                "\n\t           14 T molina st purok 6-B "+
            "\n\t              Alabang Muntinlupa City  "+
            "\nOperator: Micko Mendoza"+
            "\n\t----------------------------------------------------------------"+
            "\n\n\t   "+order+"\nTotal "+ptotal+
"\nCash "+pay+
"\nChange "+change+
            "\n----------------------------------------------------------------"+
            "\n\n \t            Thanks For buying!!!!!"+
                            "\n\t  This Serve as an official reciept DTSN:41D983"+
            "\n     \t       For Delivery Dial (519-6936)"+
            "\n    \t               Feedbacks"+
            "\n  \t             micko.mendoza@yahoo.com"
    );
                                    y=0;
                                    z=0;
                                    x=1;
                                    gtotal = gtotal+ptotal;
                                    trans++;
                                    order="";
                                    transaction = transaction+"Transaction "+ trans+ " "+ptotal+"\n";//No of transactions
                                    ptotal = 0;
                                    do{
                                        con=Integer.parseInt(JOptionPane.showInputDialog("Next Customer?\n[1] Yes\n[0] No"));
                                        if(con==1)
                                            break;
                                        else if(con==0)
                                        {
                                            JOptionPane.showMessageDialog(null,transaction+"Total sales: " + gtotal,"Transactions",JOptionPane.INFORMATION_MESSAGE);
                                            System.exit(0);
                                        }
                    else
                    {
                        JOptionPane.showMessageDialog(null,"Invalid Choice!","Error",JOptionPane.ERROR_MESSAGE);
                        continue;
                    }

                }while(con==1);
                                    break;
                                }
                            else
                                {
                                    JOptionPane.showMessageDialog(null,"Kulang pera mo");

                                    continue;
                                }
                            }while(z==1);//do3

                    }
                    else
                    {
                        JOptionPane.showMessageDialog(null,"Intiger lang pwede","Continue",JOptionPane.ERROR_MESSAGE);
                        y=1;
                        continue;
                    }
                }   while(y==1);//do2




                continue;



}   
}
}

2 个答案:

答案 0 :(得分:7)

您在break之前有一个无条件的switch

顺便说一下,我认为这是了解功能以及如何使用它们使代码更加模块化的最佳时机。

答案 1 :(得分:0)

评论休息声明

import javax.swing。;     import java.awt。;

public class Test{
public static void main(String[] args) 

{
int choice=0,food=0,c=0,con,x=1,y=1,z=1,q=1,trans=0,price=0 ,qty,gtotal=0,ptotal=0,pay,change,total=0,ord;
String order="",bibilhin="",transaction="",A;




                   ImageIcon welcome = new ImageIcon("welcome.jpg");
            ImageIcon chip = new ImageIcon("chip.jpg");
            ImageIcon rc = new ImageIcon("rc.jpg");
            ImageIcon stick = new ImageIcon("stick.jpg");
            ImageIcon pancit = new ImageIcon("pancit.jpg");
            ImageIcon jampong = new ImageIcon("jampong.jpg");
            ImageIcon chups = new ImageIcon("chups.jpg");
            ImageIcon egg = new ImageIcon("egg.jpg");
            A=JOptionPane.showInputDialog("Enter your name:");              ImageIcon hansel = new ImageIcon("hansel.jpg");

JOptionPane.showMessageDialog(null,"Sir/Ma`am \n "+A+"\n Welcome\n to Mang Inasal\n Please Choose The\n product you want to buy","Welcome" ,JOptionPane.PLAIN_MESSAGE,welcome);
    while(x==1) 
            {
            c=Integer.parseInt(JOptionPane.showInputDialog("  Categories" + "\n" +"[1] Drinks" + "\n" + "[2] Foods"));



    if(c==1)
        {choice=Integer.parseInt(JOptionPane.showInputDialog("DRINKS" +"\n"
                        + "[1] Lemonade" + "\n"
                        + "[2] Coca Cola" + "\n"
                        + "[3] Sprite" + "\n"
                        + "[4] Mountain Dew" + "\n"
                        + "[5] Pepsi" + "\n"
                        + "[6] Cofee" +"\n"
                        + "[7] Hot Choco" +  "\n"
                        + "[8] Nestie Iced Tea" +"\n"
                        + "[9] Exit" +"\n"
                        + "Enter Your Choice:"));
    if(c==2)
        food=Integer.parseInt(JOptionPane.showInputDialog("Food" +"\n"
                        + "[1] L" + "\n"
                        + "[2] Coca Cola" + "\n"
                        + "[3] Sprite" + "\n"
                        + "[4] Mountain Dew" + "\n"
                        + "[5] Pepsi" + "\n"
                        + "[6] Cofee" +"\n"
                        + "[7] Hot Choco" +  "\n"
                        + "[8] Nestie Iced Tea" +"\n"
                        + "[9] Exit" +"\n"
                        + "Enter Your Choice:"));   

    }

        switch(choice)
            {
                case 1:
                    price = 20;
                    bibilhin= " Lemonade";
                    break;
                case 2:
                    price = 20;
                    bibilhin= "Coca Cola ";
                    break;
                case 3:
                    price =820;
                    bibilhin = "Sprite";
                    break;
                case 4:
                    price =205;
                    bibilhin= "Mountain dew";
                    break;
                case 5:
                    price =20;
                    bibilhin= "Pepsi";
                    break;
                case 6:
                    price =25;
                    bibilhin= "Cofee ";
                    break;
                case 7:
                    price =25;
                    bibilhin= "Hot Choco";
                    break;
                case 8:
                    price = 20;
                    bibilhin= "Nestie Ice tea";
                    break;
                case 9:
                    JOptionPane.showMessageDialog(null,transaction+"Total sales: " + gtotal,"Transactions",JOptionPane.INFORMATION_MESSAGE);
                    JOptionPane.showMessageDialog(null,"You are about to exit!","Exit",JOptionPane.WARNING_MESSAGE);
                    do{
                        con=Integer.parseInt(JOptionPane.showInputDialog("Are you sure you want to exit?\n[1] Yes\n[0] No"));
                        if(con==1)
                            System.exit(0);
                        else if(con==1)
                        {
                            JOptionPane.showMessageDialog(null,"THANK YOU!\nGood Bye!","Exit",JOptionPane.ERROR_MESSAGE);
                            break;

                        }
                        else
                        {
                            JOptionPane.showMessageDialog(null,"Invalid Choice!","Error",JOptionPane.ERROR_MESSAGE);
                            con=1;
                        }

                       }while(con==1);
                       continue;
                default:
                    JOptionPane.showMessageDialog(null,"Invalid Choice!","ERROR",JOptionPane.ERROR_MESSAGE);
}

            do{//do1

            qty = Integer.parseInt(JOptionPane.showInputDialog("Quantity:"));

            if (qty>0)
                break;
            else
            {
                JOptionPane.showMessageDialog(null,"Invalid Input!","Error",JOptionPane.ERROR_MESSAGE);
                continue;
            }
            }while(q==1);//end do1

            total = price * qty;
            ptotal = ptotal+total;
            order = order +bibilhin+"                 "+qty+"                  "+price+"="+total+"\n";

            do  {//do2
            con = Integer.parseInt(JOptionPane.showInputDialog("Continue?[1] yes [0] no"));
                    if(con==1)
                    {

                        break;
                    }
                    else if(con==0)
                    {

                        do{
pay = Integer.parseInt(JOptionPane.showInputDialog(order+"Total " +ptotal+"\nEnter Payment:"));
if(pay>=ptotal)
                                {

change = pay-ptotal;
JOptionPane.showMessageDialog(null,"  \t                    Mang Inasal"+
            "\n\t           14 T molina st purok 6-B "+
            "\n\t              Alabang Muntinlupa City  "+
            "\nOperator: Micko Mendoza"+
            "\n\t----------------------------------------------------------------"+
            "\n\n\t   "+order+"\nTotal "+ptotal+
"\nCash "+pay+
"\nChange "+change+
            "\n----------------------------------------------------------------"+
            "\n\n \t            Thanks For buying!!!!!"+
                            "\n\t  This Serve as an official reciept DTSN:41D983"+
            "\n     \t       For Delivery Dial (519-6936)"+
            "\n    \t               Feedbacks"+
            "\n  \t             micko.mendoza@yahoo.com"
);
                                    y=0;
                                    z=0;
                                    x=1;
                                    gtotal = gtotal+ptotal;
                                    trans++;
                                    order="";
                                    transaction = transaction+"Transaction "+ trans+ " "+ptotal+"\n";//No of transactions
                                    ptotal = 0;
                                    do{
                                        con=Integer.parseInt(JOptionPane.showInputDialog("Next Customer?\n[1] Yes\n[0] No"));
                                        if(con==1)
                                            break;
                                        else if(con==0)
                                        {
                                            JOptionPane.showMessageDialog(null,transaction+"Total sales: " + gtotal,"Transactions",JOptionPane.INFORMATION_MESSAGE);
                                            System.exit(0);
                                        }
                    else
                    {
                        JOptionPane.showMessageDialog(null,"Invalid Choice!","Error",JOptionPane.ERROR_MESSAGE);
                        continue;
                    }

                }while(con==1);
                                    break;
                                }
                            else
                                {
                                    JOptionPane.showMessageDialog(null,"Kulang pera mo");

                                    continue;
                                }
                            }while(z==1);//do3

                    }
                    else
                    {
                        JOptionPane.showMessageDialog(null,"Intiger lang pwede","Continue",JOptionPane.ERROR_MESSAGE);
                        y=1;
                        continue;
                    }
                }   while(y==1);//do2

            //    break;




        switch(food)
            {
                case 11:
                    price = 20;
                    bibilhin= " Lemonade";
                    break;
                case 12:
                    price = 20;
                    bibilhin= "Coca Cola ";
                    break;
                case 13:
                    price =820;
                    bibilhin = "Sprite";
                    break;
                case 14:
                    price =205;
                    bibilhin= "Mountain dew";
                    break;
                case 15:
                    price =20;
                    bibilhin= "Pepsi";
                    break;
                case 16:
                    price =25;
                    bibilhin= "Cofee ";
                    break;
                case 17:
                    price =25;
                    bibilhin= "Hot Choco";
                    break;
                case 18:
                    price = 20;
                    bibilhin= "Nestie Ice tea";
                    break;
                case 19:
                    JOptionPane.showMessageDialog(null,transaction+"Total sales: " + gtotal,"Transactions",JOptionPane.INFORMATION_MESSAGE);
                    JOptionPane.showMessageDialog(null,"You are about to exit!","Exit",JOptionPane.WARNING_MESSAGE);
                    do{
                        con=Integer.parseInt(JOptionPane.showInputDialog("Are you sure you want to exit?\n[1] Yes\n[0] No"));
                        if(con==1)
                            System.exit(0);
                        else if(con==1)
                        {
                            JOptionPane.showMessageDialog(null,"THANK YOU!\nGood Bye!","Exit",JOptionPane.ERROR_MESSAGE);
                            break;

                        }
                        else
                        {
                            JOptionPane.showMessageDialog(null,"Invalid Choice!","Error",JOptionPane.ERROR_MESSAGE);
                            con=1;
                        }

                       }while(con==1);
                       continue;
                default:
                    JOptionPane.showMessageDialog(null,"Invalid Choice!","ERROR",JOptionPane.ERROR_MESSAGE);
}

            do{//do1

            qty = Integer.parseInt(JOptionPane.showInputDialog("Quantity:"));

            if (qty>0)
                break;
            else
            {
                JOptionPane.showMessageDialog(null,"Invalid Input!","Error",JOptionPane.ERROR_MESSAGE);
                continue;
            }
            }while(q==1);//end do1

            total = price * qty;
            ptotal = ptotal+total;
            order = order +bibilhin+"                 "+qty+"                  "+price+"="+total+"\n";

            do  {//do2
            con = Integer.parseInt(JOptionPane.showInputDialog("Continue?[1] yes [0] no"));
                    if(con==1)
                    {

                        break;
                    }
                    else if(con==0)
                    {

                        do{
pay = Integer.parseInt(JOptionPane.showInputDialog(order+"Total " +ptotal+"\nEnter Payment:"));
if(pay>=ptotal)
                                {

change = pay-ptotal;
JOptionPane.showMessageDialog(null,"  \t                    Mang Inasal"+
                "\n\t           14 T molina st purok 6-B "+
            "\n\t              Alabang Muntinlupa City  "+
            "\nOperator: Micko Mendoza"+
            "\n\t----------------------------------------------------------------"+
            "\n\n\t   "+order+"\nTotal "+ptotal+
"\nCash "+pay+
"\nChange "+change+
            "\n----------------------------------------------------------------"+
            "\n\n \t            Thanks For buying!!!!!"+
                            "\n\t  This Serve as an official reciept DTSN:41D983"+
            "\n     \t       For Delivery Dial (519-6936)"+
            "\n    \t               Feedbacks"+
            "\n  \t             micko.mendoza@yahoo.com"
    );
                                    y=0;
                                    z=0;
                                    x=1;
                                    gtotal = gtotal+ptotal;
                                    trans++;
                                    order="";
                                    transaction = transaction+"Transaction "+ trans+ " "+ptotal+"\n";//No of transactions
                                    ptotal = 0;
                                    do{
                                        con=Integer.parseInt(JOptionPane.showInputDialog("Next Customer?\n[1] Yes\n[0] No"));
                                        if(con==1)
                                            break;
                                        else if(con==0)
                                        {
                                            JOptionPane.showMessageDialog(null,transaction+"Total sales: " + gtotal,"Transactions",JOptionPane.INFORMATION_MESSAGE);
                                            System.exit(0);
                                        }
                    else
                    {
                        JOptionPane.showMessageDialog(null,"Invalid Choice!","Error",JOptionPane.ERROR_MESSAGE);
                        continue;
                    }

                }while(con==1);
                                    break;
                                }
                            else
                                {
                                    JOptionPane.showMessageDialog(null,"Kulang pera mo");

                                    continue;
                                }
                            }while(z==1);//do3

                    }
                    else
                    {
                        JOptionPane.showMessageDialog(null,"Intiger lang pwede","Continue",JOptionPane.ERROR_MESSAGE);
                        y=1;
                        continue;
                    }
                }   while(y==1);//do2




                continue;



}   
}
}