Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么每次执行或输入#3菜单时,我的#3菜单都不显示_Java - Fatal编程技术网

Java 为什么每次执行或输入#3菜单时,我的#3菜单都不显示

Java 为什么每次执行或输入#3菜单时,我的#3菜单都不显示,java,Java,我的输出代码有一些问题。我的#3菜单在运行时根本不显示。只有#1和#2菜单。当我进入#3时,它会显示我的#2菜单 注:#2菜单与#1菜单编码相同 这是我的密码: public static void main(String[] args) throws IOException { // TODO code application logic here BufferedReader dataIn = new BufferedReader(new InputStreamReader(

我的输出代码有一些问题。我的#3菜单在运行时根本不显示。只有#1和#2菜单。当我进入#3时,它会显示我的#2菜单

注:#2菜单与#1菜单编码相同

这是我的密码:

public static void main(String[] args) throws IOException {
    // TODO code application logic here
    BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


    int foods = 1, drinks = 2, dessert = 3;


    double sw = 10.00;
    double bg = 15.00;
    double rm = 25.00;
    double it = 20.00;
    double ck = 15.00;
    double cf = 13.00;
    double brn = 10.00;
    double dnt = 15.00;
    double payment, change;



    System.out.println(" ******* Menu ******* ");
    System.out.println("[1]Food [2]Drinks [3]Desserts");
    System.out.println("Enter Choice: ");
    foods=Integer.parseInt(dataIn.readLine());
    if (foods == 1) {

        String choice1;
        System.out.println(" [a] Sandwich - 10.00 \n [b] Burger - 15.00 \n [c] Rice Meal - 25.00");
        System.out.println("\n Enter Choice: ");
        System.out.flush();
        choice1 = br.readLine();;
        if (choice1.equals("a")) {
            System.out.println("You Chose a, Sandwich (10.00)");
            System.out.println("Enter Payment: ");
            payment=Double.parseDouble(dataIn.readLine());
           if (payment < 10) {
                System.out.println("Insufficient Funds");
           }else{
                change = payment - sw;
           System.out.println("Your Change is: "+change);
           System.out.println("Thank You!");
           }
        }
        else if (choice1.equalsIgnoreCase("b")) {
           System.out.println("You Chose e, Burger (15.00)"); 
           System.out.println("Enter Payment: ");
           payment=Double.parseDouble(dataIn.readLine());
           if (payment < 15) {
                System.out.println("Insufficient Funds");
           }else{
               change = payment - bg;
           System.out.println("Your Change is: "+change);
           System.out.println("Thank You!");
           }
        } 
        else if (choice1.equalsIgnoreCase("c")) {
           System.out.println("You Chose c, Rice Meal (25.00)"); 
           System.out.println("Enter Payment: ");
           payment=Double.parseDouble(dataIn.readLine());
           if (payment < 13) {
              System.out.println("Insufficient Funds"); 
           }else{
               change = payment - rm;
           System.out.println("Your Change is: "+change);
           System.out.println("Thank You!"); 
           }
        }     


    } else if(dessert == 3) {
        String choice3;
        System.out.println(" [g] brownies - 10.00 \n [h] donuts - 15.00");
        System.out.println("\n Enter Choice: ");
        System.out.flush();
        choice3 = br.readLine();
        if (choice3.equals("g")){
           System.out.println("You Chose g, brownies (10.00)"); 
           System.out.println("Enter Payment: ");
           payment=Double.parseDouble(dataIn.readLine());
           if(payment < 10) {
              System.out.println("Insufficient Funds");  
           }else{
               change = payment - brn;
           System.out.println("Your Change is: "+change);
           System.out.println("Thank You!");
           }
        }
    }  
} 
publicstaticvoidmain(字符串[]args)引发IOException{
//此处的TODO代码应用程序逻辑
BufferedReader dataIn=新的BufferedReader(新的InputStreamReader(System.in));
BufferedReader br=新的BufferedReader(新的InputStreamReader(System.in));
int食品=1,饮料=2,甜点=3;
双sw=10.00;
双bg=15.00;
双rm=25.00;
双倍=20.00;
双ck=15.00;
双cf=13.00;
双brn=10.00;
双dnt=15.00;
双倍支付,改变;
System.out.println(“*********菜单*******”);
System.out.println(“[1]食品[2]饮料[3]甜点”);
System.out.println(“输入选项:”);
foods=Integer.parseInt(dataIn.readLine());
如果(食物==1){
弦选择1;
System.out.println(“[a]三明治-10.00\n[b]汉堡-15.00\n[c]米饭-25.00”);
System.out.println(“\n输入选项:”);
System.out.flush();
choice1=br.readLine();;
如果(选择1.等于(“a”)){
System.out.println(“您选择了一个三明治(10.00)”;
System.out.println(“输入付款:”);
payment=Double.parseDouble(dataIn.readLine());
如果(付款<10){
System.out.println(“资金不足”);
}否则{
变更=付款-软件;
System.out.println(“您的更改为:“+Change”);
System.out.println(“谢谢!”);
}
}
else if(选择1.同等信号情况(“b”)){
System.out.println(“您选择了e,Burger(15.00)”;
System.out.println(“输入付款:”);
payment=Double.parseDouble(dataIn.readLine());
如果(付款<15){
System.out.println(“资金不足”);
}否则{
变更=付款-保函;
System.out.println(“您的更改为:“+Change”);
System.out.println(“谢谢!”);
}
} 
else if(选项1.等效信号情况(“c”)){
System.out.println(“您选择了c,米饭(25.00)”;
System.out.println(“输入付款:”);
payment=Double.parseDouble(dataIn.readLine());
如果(付款<13){
System.out.println(“资金不足”);
}否则{
变更=付款-rm;
System.out.println(“您的更改为:“+Change”);
System.out.println(“谢谢!”);
}
}     
}否则,如果(甜点==3){
弦乐选择3;
System.out.println(“[g]布朗尼-10.00\n[h]甜甜圈-15.00”);
System.out.println(“\n输入选项:”);
System.out.flush();
choice3=br.readLine();
如果(选择3.等于(“g”)){
System.out.println(“您选择了g,brownies(10.00)”;
System.out.println(“输入付款:”);
payment=Double.parseDouble(dataIn.readLine());
如果(付款<10){
System.out.println(“资金不足”);
}否则{
变更=付款-brn;
System.out.println(“您的更改为:“+Change”);
System.out.println(“谢谢!”);
}
}
}  
} 

我是不是遗漏了什么?我一直坐在那里想一些补偿方案,并在4天内完成它。

你能澄清一下“3菜单”是什么意思吗?什么是输入,什么是预期输出,什么是实际输出?(请更新问题以包含这些信息,而不是仅仅回复我的评论)。您正在阅读一个名为
foods
的变量。然后,如果甜点==3,则测试
,这是毫无意义的。我想你的意思是如果食物=3的话。另外,你甚至没有为饮料菜单做任何事情,所以我猜你错过了,但是如果你检查饮料=2,那么这个条件总是正确的,所以你永远不会进入你的第三个菜单。#2代码与在#1中编码是一样的,我的#3是问题,我应该把甜点=Integer.parseInt(dataIn.readLine()); 也