在我设计的一个模拟多米诺骨牌家庭的java项目中,有一个错误,代码多次接受我输入的大小 import java.io.*; 班级披萨派递 { BufferedReader br=新的BufferedReader(新的InputStreamReader(Sy

在我设计的一个模拟多米诺骨牌家庭的java项目中,有一个错误,代码多次接受我输入的大小 import java.io.*; 班级披萨派递 { BufferedReader br=新的BufferedReader(新的InputStreamReader(Sy,java,error-handling,bluej,Java,Error Handling,Bluej,在我设计的一个模拟多米诺骨牌家庭的java项目中,有一个错误,代码多次接受我输入的大小 import java.io.*; 班级披萨派递 { BufferedReader br=新的BufferedReader(新的InputStreamReader(System.in)); 串比萨[]={“玛格丽塔”、“双奶酪玛格丽塔”、“农家乐”、“高级素食”、“奶酪玉米”、“辣味香肠比萨”、“PERI-PERI鸡肉”、“非素食至尊”、“鸡肉嘉年华”、“鸡肉香肠比萨”}; int smallprice[]=

在我设计的一个模拟多米诺骨牌家庭的java项目中,有一个错误,代码多次接受我输入的大小
import java.io.*;
班级披萨派递
{
BufferedReader br=新的BufferedReader(新的InputStreamReader(System.in));
串比萨[]={“玛格丽塔”、“双奶酪玛格丽塔”、“农家乐”、“高级素食”、“奶酪玉米”、“辣味香肠比萨”、“PERI-PERI鸡肉”、“非素食至尊”、“鸡肉嘉年华”、“鸡肉香肠比萨”};
int smallprice[]={1953002853523520500285355300};
int mediumprice[]={245380325405285275380355405345};
国际大价格[]={30543540495305435425495435};
串边[]={“大蒜面包条”、“填充大蒜面包条”、“巧克力熔岩蛋糕”、“可口可乐”};
int sideprice[]={15520524575};
字符串购物车[]=新字符串[100];
国际票据[]=新国际票据[100];
int k=0,区域代码;
字符串cont、街道、房屋、区域;
字符串名;
双倍合计=0.0;
长phno;
INTF,标志,成功;
public void menu()引发IOException
{
字符串选择;
int-ch;
System.out.println(“******************欢迎使用多米诺骨牌比萨饼上门递送”********************”);
System.out.println(“蔬菜比萨饼”);
System.out.println(“1.玛格丽塔-一种非常受欢迎的玛格丽塔,上面有一层美味浓郁的单一奶酪”);
System.out.println(“2.双奶酪玛格丽塔-一直受欢迎的玛格丽塔-加上额外的奶酪….渗出物”);
System.out.println(“3.农家乐-一种蔬菜上的比萨饼!看看这令人垂涎欲滴的酥脆辣椒、多汁蘑菇和新鲜西红柿”);
System.out.println(“4.高级素食主义者-对于一个素食主义者来说,想要为素食爱好者吃奶油披萨,就是这个”);
System.out.println(“5.奶酪和玉米——奶酪(成吨)和玉米——还有什么其他人想要的?”;
System.out.println(“非素食比萨”);
System.out.println(“6.辣味香肠比萨——献给所有喜欢经典非素食比萨的人”);
System.out.println(“7.PERI-PERI鸡肉-胡椒烤鸡和红辣椒:完美的组合”);
System.out.println(“8.非素食至尊-咬入至尊的黑橄榄、洋葱、烤蘑菇、胡椒烤鸡、烤鸡、烤鸡锉刀”);
System.out.println(“9.鸡肉节-美味鸡肉的节日,用于精炼味蕾”);
System.out.println(“10.鸡肉香肠-经典”);
系统输出打印(“侧面和饮料”);
System.out.println(“11.大蒜面包条”);
System.out.println(“12.蒜蓉面包”);
System.out.println(“13.巧克力熔岩蛋糕”);
System.out.println(“14.可口可乐(500ml)”);
System.out.println(“您可以输入15以退出”);
做
{
System.out.println(“输入您选择的产品”);
choice=br.readLine();
ch=Integer.parseInt(0+choice.replaceAll(“\\D+”,”);
如果(ch0)
{
开关(ch)
{
案例1:
购物车[k]=比萨饼[ch-1];
如果(size()==1)
清单[k]=小价格[ch-1];
else if(size()==2)
比尔[k]=中等价格[ch-1];
else if(size()==3)
票据[k]=大额价格[ch-1];
System.out.println(“价格为:“+bill[k]);
System.out.println(“项目“+cart[k]+”已添加到您的购物车中”);
k++;
打破
案例2:
购物车[k]=比萨饼[ch-1];
如果(size()==1)
清单[k]=小价格[ch-1];
else if(size()==2)
比尔[k]=中等价格[ch-1];
else if(size()==3)
票据[k]=大额价格[ch-1];
System.out.println(“价格为:“+bill[k]);
System.out.println(“项目“+cart[k]+”已添加到您的购物车中”);
k++;
打破
案例3:
购物车[k]=比萨饼[ch-1];
如果(size()==1)
清单[k]=小价格[ch-1];
else if(size()==2)
比尔[k]=中等价格[ch-1];
else if(size()==3)
票据[k]=大额价格[ch-1];
System.out.println(“价格为:“+bill[k]);
System.out.println(“项目“+cart[k]+”已添加到您的购物车中”);
k++;
打破
案例4:
购物车[k]=比萨饼[ch-1];
如果(size()==1)
清单[k]=小价格[ch-1];
else if(size()==2)
比尔[k]=中等价格[ch-1];
else if(size()==3)
票据[k]=大额价格[ch-1];
System.out.println(“价格为:“+bill[k]);
System.out.println(“项目“+cart[k]+”已添加到您的购物车中”);
k++;
打破
案例5:
购物车[k]=比萨饼[ch-1];
如果(size()==1)
清单[k]=小价格[ch-1];
else if(size()==2)
比尔[k]=中等价格[ch-1];
else if(size()==3)
票据[k]=大额价格[ch-1];
System.out.println(“价格为:“+bill[k]);
System.out.println(“项目“+cart[k]+”已添加到您的购物车中”);
k++;
打破
import java.io.*;
class PizzaDelivery
{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String pizza[] = { "MARGHERITA", "DOUBLE CHEESE MARGHERITA" , "FARM HOUSE", "DELUXE VEGGIE" , "CHEESE N' CORN" , "PEPPERONI PIZZA" , "PERI-PERI CHICKEN" , "NON VEG SUPREME" , "CHICKEN FIESTA" , "CHICKEN SAUSAGE PIZZA" };
    int smallprice[] = { 195,300,285,355,235,205,300,285,355,300};
    int mediumprice[] = { 245,380,325,405,285,275,380,355,405,345};
    int largeprice[] = { 305,435,405,495,305,305,435,425,495,435};
    String sides[] = {"GARLIC BREADTSTICKS" , "STUFFED GARLIC BREADSTICKS" , "CHOCO LAVA CAKE" ,"COCA COLA"};
    int sideprice[] = { 155, 205 , 245 , 75};
    String cart[] = new String[100];
    int bill[] = new int[100];
    int k = 0,areacode;
    String cont,street,house,area;
    String name;
    double total=0.0;
    long phno;
    int f,flag,success;
    public void menu() throws IOException
    {
        String choice;
        int ch;
        System.out.println("**************** WELCOME TO DOMINOS PIZZA HOME DELIVERY ******************");
        System.out.println("Veg pizzas");
        System.out.println("1. MARGHERITA - A hugely popular margherita, with a deliciously tangy single cheese topping");
        System.out.println("2. DOUBLE CHEESE MARGHERITA - The ever popular margherita - loaded with extra cheese.....oodies of it");
        System.out.println("3. FARM HOUSE - A pizza that goes ballistic on veggies! Check out this mouth watering overload of crunchy crisp capsicum, succulent mushrooms and fresh tomatoes");
        System.out.println("4. DELUXE VEGGIE - For a vegetarian looking to eat the creme de la creme pizza for veggie lovers , this is it");     
        System.out.println("5. CHEESE N' CORN - Cheese(tons of it) and corn - what more could someone want?");
        System.out.println("Non-veg pizzas");    
        System.out.println("6. PEPPERONI PIZZA - for all the lovers of classic non veg pizzas out there");
        System.out.println("7. PERI-PERI CHICKEN - Pepper barbeque chicken and Red paprika : the perfect combination");
        System.out.println("8. NON VEG SUPREME - Bite into supreme delight of black olives, Onions , grilled mushrooms , pepper bbq chicken, peri-peri chicken, grilled chicken rashers");
        System.out.println("9. CHICKEN FIESTA - A fiesta of tasty chicken for the refined taste buds");
        System.out.println("10. CHICKEN SAUSAGE - A classic ");
        System.out.println("Sides and beverages");  
        System.out.println("11. GARLIC BREADSTICKS");
        System.out.println("12. STUFFED GARLIC BREAD");
        System.out.println("13. CHOCO LAVA CAKE");
        System.out.println("14. COCA COLA(500ml)");
        System.out.println("You can enter 15 to exit");
        do
        {

            System.out.println("Enter your choice of product");
            choice = br.readLine();
            ch = Integer.parseInt(0 + choice.replaceAll("\\D+",""));

            if(ch<=10 && ch>0)
            {

                switch(ch)
                {
                    case 1:  
                    cart[k] =  pizza[ch-1];
                    if(size()==1)
                        bill[k] = smallprice[ch-1];
                    else if(size()==2)
                        bill[k] = mediumprice[ch-1];
                    else if(size()==3)
                        bill[k] = largeprice[ch-1];
                    System.out.println("the price is: " + bill[k]);
                    System.out.println("The item "+ cart[k] + " has been added to your cart");
                    k++;
                    break;
                    case 2:  
                    cart[k] =  pizza[ch-1];
                    if(size()==1)
                        bill[k] = smallprice[ch-1];
                    else if(size()==2)
                        bill[k] = mediumprice[ch-1];
                    else if(size()==3)
                        bill[k] = largeprice[ch-1];
                    System.out.println("the price is: " + bill[k]);
                    System.out.println("The item "+ cart[k] + " has been added to your cart");
                    k++;
                    break;
                    case 3:  
                    cart[k] =  pizza[ch-1];
                    if(size()==1)
                        bill[k] = smallprice[ch-1];
                    else if(size()==2)
                        bill[k] = mediumprice[ch-1];
                    else if(size()==3)
                        bill[k] = largeprice[ch-1];
                    System.out.println("the price is: " + bill[k]);
                    System.out.println("The item "+ cart[k] + " has been added to your cart");
                    k++;
                    break;
                    case 4:  
                    cart[k] =  pizza[ch-1];
                    if(size()==1)
                        bill[k] = smallprice[ch-1];
                    else if(size()==2)
                        bill[k] = mediumprice[ch-1];
                    else if(size()==3)
                        bill[k] = largeprice[ch-1];
                    System.out.println("the price is: " + bill[k]);
                    System.out.println("The item "+ cart[k] + " has been added to your cart");
                    k++;
                    break;
                    case 5:  
                    cart[k] =  pizza[ch-1];
                    if(size()==1)
                        bill[k] = smallprice[ch-1];
                    else if(size()==2)
                        bill[k] = mediumprice[ch-1];
                    else if(size()==3)
                        bill[k] = largeprice[ch-1];
                    System.out.println("the price is: " + bill[k]);
                    System.out.println("The item "+ cart[k] + " has been added to your cart");
                    k++;
                    break;
                    case 6:  
                    cart[k] =  pizza[ch-1];
                    if(size()==1)
                        bill[k] = smallprice[ch-1];
                    else if(size()==2)
                        bill[k] = mediumprice[ch-1];
                    else if(size()==3)
                        bill[k] = largeprice[ch-1];
                    System.out.println("the price is: " + bill[k]);
                    System.out.println("The item "+ cart[k] + " has been added to your cart");
                    k++;
                    break;
                    case 7:  
                    cart[k] =  pizza[ch-1];
                    if(size()==1)
                        bill[k] = smallprice[ch-1];
                    else if(size()==2)
                        bill[k] = mediumprice[ch-1];
                    else if(size()==3)
                        bill[k] = largeprice[ch-1];
                    System.out.println("the price is: " + bill[k]);
                    System.out.println("The item "+ cart[k] + " has been added to your cart");
                    k++;
                    break;
                    case 8:  
                    cart[k] =  pizza[ch-1];
                    if(size()==1)
                        bill[k] = smallprice[ch-1];
                    else if(size()==2)
                        bill[k] = mediumprice[ch-1];
                    else if(size()==3)
                        bill[k] = largeprice[ch-1];
                    System.out.println("the price is: " + bill[k]);
                    System.out.println("The item "+ cart[k] + " has been added to your cart");
                    k++;
                    break;
                    case 9:  
                    cart[k] =  pizza[ch-1];
                    if(size()==1)
                        bill[k] = smallprice[ch-1];
                    else if(size()==2)
                        bill[k] = mediumprice[ch-1];
                    else if(size()==3)
                        bill[k] = largeprice[ch-1];
                    System.out.println("the price is: " + bill[k]);
                    System.out.println("The item "+ cart[k] + " has been added to your cart");
                    k++;
                    break;
                    case 10:  
                    cart[k] =  pizza[ch-1];
                    if(size()==1)
                        bill[k] = smallprice[ch-1];
                    else if(size()==2)
                        bill[k] = mediumprice[ch-1];
                    else if(size()==3)
                        bill[k] = largeprice[ch-1];
                    System.out.println("the price is: " + bill[k]);
                    System.out.println("The item "+ cart[k] + " has been added to your cart");
                    k++;
                    break;
                }
            }
            else if(ch>10 && ch<=15)
            {
                switch(ch)
                {
                    case 11:  
                    cart[k] =  sides[ch-11];              
                    bill[k] = sideprice[ch-11];
                    System.out.println("the price is: " + bill[k]);
                    System.out.println("The item "+ cart[k] + " has been added to your cart");
                    k++;
                    break;
                    case 12:  
                    cart[k] =  sides[ch-11];                
                    bill[k] = sideprice[ch-11];
                    System.out.println("the price is: " + bill[k]);
                    System.out.println("The item "+ cart[k] + " has been added to your cart");
                    k++;
                    break;
                    case 13:  
                    cart[k] =  sides[ch-11];                
                    bill[k] = sideprice[ch-11];
                    System.out.println("the price is: " + bill[k]);
                    System.out.println("The item "+ cart[k] + " has been added to your cart");
                    k++;
                    break;
                    case 14:  
                    cart[k] =  sides[ch-11];                
                    bill[k] = sideprice[ch-11];
                    System.out.println("the price is: " + bill[k]);
                    System.out.println("The item "+ cart[k] + " has been added to your cart");
                    k++;
                    break;
                    case 15: System.exit(0);
                }

            }
            else
            {
                System.out.println("You have entered a number that doesn't correspond to any item");

            }

                System.out.println("Do you want to continue buying? \n If yes, please enter \"yes\" else enter \"no\" . If you want to exit , please enter yes and then press 15");
                cont = br.readLine();
                if(cont.equalsIgnoreCase("No")==true)
                {
                    return;
                }
                if( cont.equalsIgnoreCase("yes")==true)
                {

                }
                else
                {
                    System.out.println("The input entered by you is not correct. Please enter yes or no");
                    cont = br.readLine();
                }

        }while(cont.equalsIgnoreCase("Yes"));

    }
    int size() throws IOException
    {    
        int size ;
        int f=0;

        do
        {
            System.out.println("Enter the number for the size of the pizza you want (1.Small/2,Medium/3.Large):");
            size = Integer.parseInt(br.readLine());
            if(size>=1 && size<=3)
            {
               break;
            }
            if(size>3 && size<1)
            {
                System.out.println("That number doesnt correspond to a size");
                System.out.println("Please enter a valid choice");
                f=0;
            }    
        }while(f==0);
        return size;
    }
    void bill() throws IOException
    {
        for(int i = k-1;i>=0;i--)
            total+= bill[i];
        System.out.println ("\n\n*********************************  BILL  *****************************************");
        System.out.println ("\n NAME: "+ name);
        System.out.println ("\n-----------------------------------------------------------------------------------------");
        System.out.println ("\nITEMS \t\t\t\t \t COST  ");
        System.out.println ("\n-----------------------------------------------------------------------------------------");
        for(int i = 0;i<k;i++)
        {
            System.out.println(cart[i] + "\t \t \t \t \t" + bill[i]);
        }
        System.out.println("\n Total : \t \t \t \t \t \t" + total);
        System.out.println("SGST: 2.5% \t \t \t \t \t " + (0.025 * total));
        System.out.println("CGST: 2.5% \t \t \t \t \t " + (0.025 * total));
        System.out.println("GRAND TOTAL: \t \t \t \t \t" + (1.05* total));

        System.out.println ("\n************************************************************************************");
        System.out.println ("\n ENTER YOUR AREA NAME ");
        String area =br.readLine();
        System.out.println("\n ENTER YOUR STREET NAME");
        String street = br.readLine();
        System.out.println("\n ENTER YOUR HOUSE NAME , FLAT NUMBER(IF ANY)");
        String house = br.readLine();
        System.out.println("\n ENTER YOUR KOLKATA AREA CODE WITHOUT A SPACE IN BETWEEN");

        do
        {
            try
            {
                f=0;
                areacode = Integer.parseInt(br.readLine());
                if(areacode <= 700000 && areacode >= 700163) 
                {
                    f++;
                    System.out.println("Your area code is not valid");
                    System.out.println("Enter a valid area code");
                }
            }
            catch(Exception e)
            {

                System.out.println("Your area code is not valid");
                System.out.println("Enter a valid area code");
                areacode = Integer.parseInt(br.readLine());
                f++;
            }

        }while(f>0);

        System.out.println ("\n PAYMENT CAN BE MADE IN THE FOLLOWING WAYS:");
        System.out.println ();
        System.out.println ("1. CREDIT CARD OR DEBIT CARD");        
        System.out.println ("2. CASH ON DELIVERY");
        System.out.println ("\n\n ENTER YOUR CHOICE");
        for(int f = -1;f==-1;)
        {
            int paychoice =Integer.parseInt(br.readLine());
            switch (paychoice)
            {
                case 1:
                System.out.println ("ENTER CREDIT/DEBIT CARD NO.:");
                String ccn=br.readLine();
                System.out.println ("ENTER CVV NO.:");
                String cvv=br.readLine();
                System.out.println("Enter the date till which the card is valid");
                String date = br.readLine();
                System.out.println("Enter the name on the card");
                String name_card = br.readLine();
                System.out.println ("\n\n CONGRATULATIONS!!!!!! THE PAYMENT HAS BEEN MADE");   
                f=1;
                break;
                case 2:                
                f=1;
                break;
                default:
                System.out.println ("OOPS!!! WRONG CHOICE");
                System.out.println("Enter your choice again");
                f=-1;
            }

        }
        do
        {
            flag=0;
            System.out.println("Please enter your mobile number");
            System.out.print("+91");
            phno = Long.parseLong(br.readLine());
            int c = 0;
            for(long i = phno;i!=0;i/=10)
            {
                int d = (int)(phno%i);
                c++;
            }

            if(c!=10)
            {
                System.out.println("The entered number is not valid. Please try again");
                flag++;
            }
        }while(flag>0);

        System.out.println("Please enter your email id");
        String emailid = br.readLine();            
        System.out.println("Your product will be delivered within 30mins. If the delivery time is more than 30 mins , you will not have to pay anything. However,if prior information is given regarding any delay in delivery time, this rule will not be valid. Further details will be provided via SMS and email");           
        System.out.println ("                 \n\nFOR FUTHER DETAILS AND QUERIES, CONTACT us using the queries section of dominos website or at the number 033 2461 4505");
        System.out.println ("\n\n******************************************************  THANK YOU  ******************************************************");
        System.out.println ("\n\n************************************************ !!!!! VISIT AGAIN !!!!!  ***********************************************");

    }

    void main() throws IOException
    {
        do
        {
            System.out.println("Enter your name");
            name = br.readLine();
            success=0;
            for(int i = 0;i<name.length();i++)
            {
                char ch = name.charAt(i);
                if(ch==' ')
                {
                    success++;
                }


            }
            if(success==0)
            {
                    System.out.println("Please enter your full name separated by a space");                
            }
        }while(success==0);
        PizzaDelivery obj = new PizzaDelivery();
        obj.menu();
        obj.bill();
    }
}
if(size()==1)
    bill[k] = smallprice[ch-1];
else if(size()==2)
    bill[k] = mediumprice[ch-1];
else if(size()==3)
    bill[k] = largeprice[ch-1];