Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.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 系统输出打印项次(“到期金额”); System.out.println(“**********”); 系统输出打印项次(“小计:+x格式(金额)); System.out.println(“总计:+x.format(amounted)); System.out.println(“请输入投标金额”); double k=double.parseDouble(input.readLine()); //双kk=数学功率(1+k,k);不需要 amountweed=(amountweed-k); 如果(amountheed==0) { System.out.println(“感谢您付了零钱!”); 系统出口(0); } else if(未计算的数量0) { 系统输出打印项次(“到期金额”); System.out.println(“**********”); 系统输出打印项次(“小计:+x格式(金额)); System.out.println(“总计:+x.format(amounted)); System.out.println(“请输入投标金额”); double k=double.parseDouble(input.readLine()); //double kk=Math.pow(1+k,k);无需 amountweed=(amountweed-k); 如果(amountheed==0) { System.out.println(“感谢您付了零钱!”); 系统出口(0); } else if(未计算的数量_Java_Double - Fatal编程技术网

Java 系统输出打印项次(“到期金额”); System.out.println(“**********”); 系统输出打印项次(“小计:+x格式(金额)); System.out.println(“总计:+x.format(amounted)); System.out.println(“请输入投标金额”); double k=double.parseDouble(input.readLine()); //双kk=数学功率(1+k,k);不需要 amountweed=(amountweed-k); 如果(amountheed==0) { System.out.println(“感谢您付了零钱!”); 系统出口(0); } else if(未计算的数量0) { 系统输出打印项次(“到期金额”); System.out.println(“**********”); 系统输出打印项次(“小计:+x格式(金额)); System.out.println(“总计:+x.format(amounted)); System.out.println(“请输入投标金额”); double k=double.parseDouble(input.readLine()); //double kk=Math.pow(1+k,k);无需 amountweed=(amountweed-k); 如果(amountheed==0) { System.out.println(“感谢您付了零钱!”); 系统出口(0); } else if(未计算的数量

Java 系统输出打印项次(“到期金额”); System.out.println(“**********”); 系统输出打印项次(“小计:+x格式(金额)); System.out.println(“总计:+x.format(amounted)); System.out.println(“请输入投标金额”); double k=double.parseDouble(input.readLine()); //双kk=数学功率(1+k,k);不需要 amountweed=(amountweed-k); 如果(amountheed==0) { System.out.println(“感谢您付了零钱!”); 系统出口(0); } else if(未计算的数量0) { 系统输出打印项次(“到期金额”); System.out.println(“**********”); 系统输出打印项次(“小计:+x格式(金额)); System.out.println(“总计:+x.format(amounted)); System.out.println(“请输入投标金额”); double k=double.parseDouble(input.readLine()); //double kk=Math.pow(1+k,k);无需 amountweed=(amountweed-k); 如果(amountheed==0) { System.out.println(“感谢您付了零钱!”); 系统出口(0); } else if(未计算的数量,java,double,Java,Double,第一件事 您不需要不必要的while循环(在下面的代码中修复) 不需要Math.pow(1+a,a)(在下面的代码中修复) amount1、amount2等可以声明为局部变量(在下面的代码中不固定),因为它不会造成损害 private static void Burger(BufferedReader输入)抛出IOException { System.out.println(“您想要多少汉堡?”); inta=Integer.parseInt(input.readLine()); //doubl

第一件事

  • 您不需要不必要的while循环(在下面的代码中修复)
  • 不需要Math.pow(1+a,a)(在下面的代码中修复)
  • amount1、amount2等可以声明为局部变量(在下面的代码中不固定),因为它不会造成损害
  • private static void Burger(BufferedReader输入)抛出IOException
    {
    System.out.println(“您想要多少汉堡?”);
    inta=Integer.parseInt(input.readLine());
    //double aaa=Math.pow(1+a,a);//为什么会这样???
    金额1=((双倍)a*13.49);
    金额+=金额1;
    }
    私有静态void(BufferedReader输入)引发IOException
    {
    System.out.println(“您想要多少份意大利面?”);
    intb=Integer.parseInt(input.readLine());
    //double bbb=Math.pow(1+b,b);您不需要这个
    金额2=((双倍)b*16.79);
    金额+=金额2;
    } 
    私有静态void沙拉(BufferedReader输入)引发IOException
    {
    System.out.println(“您想要多少沙拉?”);
    int c=Integer.parseInt(input.readLine());
    //double ccc=Math.pow(1+c,c);不再需要这个
    金额3=((双倍)c*13.49);
    金额+=金额3;
    }
    }私有静态void Salmon(BufferedReader输入)引发IOException
    {
    System.out.println(“您想要多少份鲑鱼订单?”);
    intd=Integer.parseInt(input.readLine());
    //双ddd=数学功率(1+d,d);无需
    金额4=((双倍)d*18.99);
    金额+=金额4;
    }
    私有静态void Chicken(BufferedReader输入)引发IOException
    {
    System.out.println(“您想要多少份鸡肉?”;
    int e=Integer.parseInt(input.readLine());
    金额5=((双)e*16.99);
    金额+=金额5;
    }
    私有静态void Nachos(BufferedReader输入)引发IOException
    {
    System.out.println(“您想要多少份玉米片?”;
    intf=Integer.parseInt(input.readLine());
    金额6=((双倍)f*13.99);
    金额+=金额6;
    }
    私有静态void Soup(BufferedReader输入)引发IOException
    {
    System.out.println(“您想要多少份汤?”);
    int g=Integer.parseInt(input.readLine());
    金额7=((双倍)g*6.99);
    金额+=金额7;
    }
    私有静态void Fajitas(BufferedReader输入)引发IOException
    {
    System.out.println(“您想要多少份2份法吉塔的订单?”);
    inth=Integer.parseInt(input.readLine());
    金额8=((双倍)h*18.49);
    金额+=金额8;
    }
    私有静态无效条(BufferedReader输入)引发IOException
    {
    System.out.println(“您想要多少排排骨?”);
    inti=Integer.parseInt(input.readLine());
    金额9=((双倍)i*23.99);
    金额+=金额9;
    }
    私有静态void Calamari(BufferedReader输入)引发IOException
    {
    System.out.println(“您想要多少份Calamari?”);
    intj=Integer.parseInt(input.readLine());
    金额10=((双倍)j*9.99);
    金额+=金额10;
    }
    私有静态无效清除(BufferedReader输入)引发IOException
    {
    金额=0;
    }
    私有静态void Finish(BufferedReader输入)引发IOException
    {
    Amuntowed=金额*1.13
    DecimalFormat x=新的DecimalFormat(“####.##”);
    while(amounted>0)
    {
    系统输出打印项次(“到期金额”);
    System.out.println(“**********”);
    系统输出打印项次(“小计:+x格式(金额));
    System.out.println(“总计:+x.format(amounted));
    System.out.println(“请输入投标金额”);
    double k=double.parseDouble(input.readLine());
    //double kk=Math.pow(1+k,k);无需
    amountweed=(amountweed-k);
    如果(amountheed==0)
    {
    System.out.println(“感谢您付了零钱!”);
    系统出口(0);
    }
    else if(未计算的数量<0)
    {
    System.out.println(“到期变更:+x.format(amounted*-1.00));
    系统出口(0);
    }
    其他的
    {
    System.out.println(“仍欠金额:+x.format(amounted));
    }
    }
    }
    
    如何在代码中实现这一点?我不太擅长编程。这花了我一个多月的时间,这只是我第一年编写的代码。这不是浮点舍入错误,因为对于涉及双精度的简单计算,它给出的答案在正确答案的10^15分之一以内,而不是完全疯狂的答案。@Zutty在这种情况下这有什么帮助?顺便说一句,为了平衡起见,我总是建议人们使用
    double
    来赚钱@user1965245作为一般规则,在发布问题之前,尝试将问题降至最低限度。通常,如果你将程序缩减到存在问题的最低限度,你会自己找到解决方案(使你成为一名更好的程序员),或者至少,这样的人会更乐于提供帮助。例如,只有当您拥有全部10个菜单项时才会发生错误,如果不将其缩减为1,您是否需要键盘输入,或者如果main方法只是针对押韵问题运行了一系列预先生成的命令+1,错误还会发生。我如何在代码中实现这一点?我不太擅长编程。这花了我一个多月的时间,这只是我第一年的编码。这不是浮点舍入错误,因为
    import java.io.*;
    import java.text.*;
    import java.util.*;
    
    public class JavaBurger
    {
        public static double amountowed = 0;
        public static double amount;
        public static double amount1 = 0;
        public static double amount2 = 0;
        public static double amount3 = 0;
        public static double amount4 = 0;
        public static double amount5 = 0;
        public static double amount6 = 0;
        public static double amount7 = 0;
        public static double amount8 = 0;
        public static double amount9 = 0;
        public static double amount10 = 0;
    
    
        static ArrayList MenuItems = new ArrayList();
    
        public static void main(String[] args)
        {
            InputStreamReader inp = null;
            BufferedReader input = null;
            int nOption  = 0;
        DecimalFormat x = new DecimalFormat("###.##");
    
    
            try
            {
                inp = new InputStreamReader(System.in);
                input = new BufferedReader(inp);
                while(true)
                {
            System.out.println("Choose a Menu Option");
                    System.out.println("1. Burger - 13.49");
                    System.out.println("2. Pasta - 16.79");
                    System.out.println("3. Salad - 13.49");
                    System.out.println("4. Salmon - 18.99");
                    System.out.println("5. Chicken - 16.99");
                    System.out.println("6. Nachos - 13.99");
            System.out.println("7. Soup - 6.99");
            System.out.println("8. Fajitas - 18.49");
            System.out.println("9. Ribs - 23.99");
            System.out.println("10. Calamari-9.99");
            System.out.println("11. Clear Order");
            System.out.println("12. Finish Order");
                    System.out.println("\nChoose an option(1-12) >> ");
            System.out.println("Subtotal: $" + x.format(amount));
            System.out.println("Total: $" + x.format(amount * 1.13));
            System.out.println("For error correction, choose an option and enter a negative value to void the item.");
    
                    nOption = Integer.parseInt(input.readLine());
    
                    switch(nOption)
                    {
                        case 1:
                            Burger(input);
                            break;
                case 2:
                            Pasta(input);
                            break;
                case 3:
                            Salad(input);
                            break;
                case 4:
                            Salmon(input);
                            break;
                case 5:
                            Chicken(input);
                            break;
                        case 6:
                            Nachos(input);
                            break;
                        case 7:
                            Soup(input);
                            break;
                        case 8:
                            Fajitas(input);
                            break;
                        case 9:
                            Ribs(input);
                            break;
                        case 10:
                            Calamari(input);
                            break;
                case 11:
                Clear(input);
                break;
                case 12:
                Finish(input);
                break;
    
                    }
                }
            }
            catch(Exception exp)
            {
            }
        }
    
        private static void Burger(BufferedReader input) throws IOException
        {
    
            while(true)
            {
    
                System.out.println("How many Burgers would you like? ");
            int a = Integer.parseInt(input.readLine());
    
            double aaa = Math.pow(1 + a, a);
                amount1 = (a * 13.49);
            amount += amount1;
    
    
                    break;
            }
        }
    
         private static void Pasta(BufferedReader input) throws IOException
        {
            while(true)
            {
    
                System.out.println("How many orders of Pasta would you like? ");
            int b = Integer.parseInt(input.readLine());
    
            double bbb = Math.pow(1 + b, b);
                amount2 = (bbb * 16.79);
            amount += amount2;
    
    
                    break;
            }
        } private static void Salad(BufferedReader input) throws IOException
        {
            while(true)
            {
    
                System.out.println("How many Salads would you like? ");
            int c = Integer.parseInt(input.readLine());
    
            double ccc = Math.pow(1 + c, c);
                amount3 = (ccc * 13.49);
            amount += amount3;
    
    
                    break;
            }
        } private static void Salmon(BufferedReader input) throws IOException
        {
    
            while(true)
            {
    
                System.out.println("How many orders of Salmon would you like? ");
            int d = Integer.parseInt(input.readLine());
    
            double ddd = Math.pow(1 + d, d);
                amount4 = (ddd * 18.99);
            amount += amount4;
    
    
                    break;
            }
        } private static void Chicken(BufferedReader input) throws IOException
        {
    
            while(true)
            {
    
                System.out.println("How many orders of Chicken would you like? ");
            int e = Integer.parseInt(input.readLine());
    
            double eee = Math.pow(1 + e, e);
                amount5 = (eee * 16.99);
            amount += amount5;
    
    
                    break;
            }
        } private static void Nachos(BufferedReader input) throws IOException
        {
    
            while(true)
            {
    
                System.out.println("How many orders of Nachos would you like? ");
            int f = Integer.parseInt(input.readLine());
    
            double fff = Math.pow(1 + f, f);
                amount6 = (fff * 13.99);
            amount += amount6;
    
                    break;
            }
        } private static void Soup(BufferedReader input) throws IOException
        {
            while(true)
            {
    
                System.out.println("How many orders of Soup would you like? ");
            int g = Integer.parseInt(input.readLine());
    
            double ggg = Math.pow(1 + g, g);
                amount7 = (ggg * 6.99);
            amount += amount7;
    
                    break;
            }
        } private static void Fajitas(BufferedReader input) throws IOException
        {
    
            while(true)
            {
    
                System.out.println("How many orders of 2 Fajitas would you like? ");
            int h = Integer.parseInt(input.readLine());
    
            double hhh = Math.pow(1 + h, h);
                amount8 = (hhh * 18.49);
            amount += amount8;
    
                    break;
            }
        } private static void Ribs(BufferedReader input) throws IOException
        {
    
            while(true)
            {
    
                System.out.println("How many racks of Ribs would you like? ");
            int i = Integer.parseInt(input.readLine());
    
            double iii = Math.pow(1 + i, i);
                amount9 = (iii * 23.99);
            amount += amount9;
    
                    break;
            }
        } private static void Calamari(BufferedReader input) throws IOException
        {
    
            while(true)
            {
    
                System.out.println("How many orders of Calamari would you like? ");
            int j = Integer.parseInt(input.readLine());
    
            double jjj = Math.pow(1 + j, j);
                amount10 = (jjj * 9.99);
            amount += amount10;
    
                    break;
            }
        } private static void Clear(BufferedReader input) throws IOException
        {
    
        while(true)
        {
    
            amount = 0;
    
            break;
        }
        } private static void Finish(BufferedReader input) throws IOException
        {
    
        while(true)
        {
    
            DecimalFormat x = new DecimalFormat("###.##");
            System.out.println("Amount Due");
            System.out.println("**********");
            System.out.println("Subtotal:" + x.format(amount));
            System.out.println("Total:" + x.format(amount * 1.13));
            System.out.println("Please enter the amount tendered");
            int k = Integer.parseInt(input.readLine());
            double kk = Math.pow(1 + k, k);
            amountowed = ((amount * 1.13) - kk);
            if(amountowed == 0)
            {
            System.out.println("Thanks for paying with exact change!");
            System.exit(0);
            }
            else if(amountowed < 0)
            {
            System.out.println("Change due:" + x.format(amountowed * -1.00));
            System.exit(0);
            }
            else
            {
            System.out.println("Amount still owed:" + x.format(amountowed * -1.00));
            }
        }
        }
    }
    
    Choose a Menu Option
    1. Burger - 13.49
    2. Pasta - 16.79
    3. Salad - 13.49
    4. Salmon - 18.99
    5. Chicken - 16.99
    6. Nachos - 13.99
    7. Soup - 6.99
    8. Fajitas - 18.49
    9. Ribs - 23.99
    10. Calamari-9.99
    11. Clear Order
    12. Finish Order
    
    Choose an option(1-12) >>
    Subtotal: $0
    Total: $0
    For error correction, choose an option and enter a negative value to void the it
    em.
    1
    How many Burgers would you like?
    1
    Choose a Menu Option
    1. Burger - 13.49
    2. Pasta - 16.79
    3. Salad - 13.49
    4. Salmon - 18.99
    5. Chicken - 16.99
    6. Nachos - 13.99
    7. Soup - 6.99
    8. Fajitas - 18.49
    9. Ribs - 23.99
    10. Calamari-9.99
    11. Clear Order
    12. Finish Order
    
    Choose an option(1-12) >>
    Subtotal: $13.49
    Total: $15.24
    For error correction, choose an option and enter a negative value to void the it
    em.
    12
    Amount Due
    **********
    Subtotal:13.49
    Total:15.24
    Please enter the amount tendered
    100
    Change due:270481382942152600000000000000000000000000000000000000000000000000000
    00000000000000000000000000000000000000000000000000000000000000000000000000000000
    0000000000000000000000000000000000000000000000000000
    
    double kk = Math.pow(1 + k, k);
    
     int e = Integer.parseInt(input.readLine());
     double eee = Math.pow(1 + e, e);
    
     double eee = Math.pow(1 + 5, 5)
    
    private static void Burger(BufferedReader input) throws IOException
    {
        System.out.println("How many Burgers would you like? ");
        int a = Integer.parseInt(input.readLine());
      //  double aaa = Math.pow(1 + a, a);// Why THis??? 
      amount1 = ((double)a * 13.49);
        amount += amount1;
    
    }
    
     private static void Pasta(BufferedReader input) throws IOException
    {
        System.out.println("How many orders of Pasta would you like? ");
        int b = Integer.parseInt(input.readLine());
    
       // double bbb = Math.pow(1 + b, b); You dont need this 
        amount2 = ((double)b * 16.79);
        amount += amount2;
    
    } 
    private static void Salad(BufferedReader input) throws IOException
    {
        System.out.println("How many Salads would you like? ");
        int c = Integer.parseInt(input.readLine());
    
        //double ccc = Math.pow(1 + c, c); No Need of this again 
            amount3 = ((double)c * 13.49);
        amount += amount3;
    
        }
    } private static void Salmon(BufferedReader input) throws IOException
    {
    
        System.out.println("How many orders of Salmon would you like? ");
        int d = Integer.parseInt(input.readLine());
    
        //double ddd = Math.pow(1 + d, d); No Need
        amount4 = ((double)d * 18.99);
        amount += amount4;
    }
     private static void Chicken(BufferedReader input) throws IOException
     {
    
        System.out.println("How many orders of Chicken would you like? ");
        int e = Integer.parseInt(input.readLine());
        amount5 = ((double)e * 16.99);
        amount += amount5;
    
    }
     private static void Nachos(BufferedReader input) throws IOException
    {
    
        System.out.println("How many orders of Nachos would you like? ");
        int f = Integer.parseInt(input.readLine());
    
        amount6 = ((double)f * 13.99);
        amount += amount6;
    
    }
     private static void Soup(BufferedReader input) throws IOException
    {
        System.out.println("How many orders of Soup would you like? ");
        int g = Integer.parseInt(input.readLine());
    
        amount7 = ((double)g * 6.99);
        amount += amount7;
    
    }
     private static void Fajitas(BufferedReader input) throws IOException
    {
        System.out.println("How many orders of 2 Fajitas would you like? ");
        int h = Integer.parseInt(input.readLine());
         amount8 = ((double)h * 18.49);
        amount += amount8;
    
    }
    private static void Ribs(BufferedReader input) throws IOException
    {
        System.out.println("How many racks of Ribs would you like? ");
        int i = Integer.parseInt(input.readLine());
         amount9 = ((double)i * 23.99);
        amount += amount9;
    
    }
     private static void Calamari(BufferedReader input) throws IOException
    {
    
        System.out.println("How many orders of Calamari would you like? ");
        int j = Integer.parseInt(input.readLine());
    
        amount10 = ((double)j * 9.99);
        amount += amount10;
    
    }
     private static void Clear(BufferedReader input) throws IOException
    {
        amount = 0;
    
    }
    private static void Finish(BufferedReader input) throws IOException
    {
    amountowed =amount * 1.13
    DecimalFormat x = new DecimalFormat("###.##");
    
    while(amountowed >0)
    {
        System.out.println("Amount Due");
        System.out.println("**********");
        System.out.println("Subtotal:" + x.format(amount));
        System.out.println("Total:" + x.format(amountowed));
        System.out.println("Please enter the amount tendered");
        double k = Double.parseDouble(input.readLine());
       // double kk = Math.pow(1 + k, k); No Need
        amountowed = (amountowed  - k);
        if(amountowed == 0)
        {
            System.out.println("Thanks for paying with exact change!");
            System.exit(0);
        }
        else if(amountowed < 0)
        {
            System.out.println("Change due:" + x.format(amountowed * -1.00));
            System.exit(0);
        }
        else
        {
            System.out.println("Amount still owed:" + x.format(amountowed));
        }
    
        }
    }