Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.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 为什么我的程序出错了?_Java_Rounding_Calculator_Tax - Fatal编程技术网

Java 为什么我的程序出错了?

Java 为什么我的程序出错了?,java,rounding,calculator,tax,Java,Rounding,Calculator,Tax,这是我的程序,从一张账单计算税款 请有人向我解释一下,我的程序中的什么导致我的程序将尖端舍入得比自动分级机输入到我的程序中的主输出更高。我找不到我的小费上涨的原因。我试过几种不同的方法,但都没有成功 import java.util.Scanner; public class R8 { public static void main(String[] args) { // TODO Auto-generated method stub //

这是我的程序,从一张账单计算税款

请有人向我解释一下,我的程序中的什么导致我的程序将尖端舍入得比自动分级机输入到我的程序中的主输出更高。我找不到我的小费上涨的原因。我试过几种不同的方法,但都没有成功

    import java.util.Scanner;

public class R8 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        //      Read all the steps carefully before beginning. Understand the larger picture.
        //      Create a new Java Project named R8, and make a class named R8.
        //      Copy the following code and paste it inside the the curly braces of the main method:
        //      // Declare variables
        String restaurantName;
        String serverName;
        double subtotal;
        double tax = 0;
        double total = 0;
        double taxRate = 0.05;
        double tipRate1 = 0.10;
        double tipRate2 = 0.15;
        double tipRate3 = 0.20;

        //      // Ask and receive input from the user
        //      Create a Scanner object, prompt the user for the name of the restaurant, and read in their input to the variable restaurantName. The restaurant can be be more than one word, like "Park Sushi."
        Scanner scanner = new Scanner(System.in);
        System.out.print("name of the restaurant: ");
        restaurantName = scanner.nextLine();

        //      Prompt the user for the name of the server. Store the value in the variable serverName. Assume the server name will always be a first and last name, separated by one space character.
        System.out.print("server name: ");
        serverName = scanner.next();
        scanner.nextLine();

        //      Prompt the user for the cost of the bill. Store the value in the variable subtotal. Assume the cost will be a double value representing dollars, for example 56.23.
        System.out.print("Total bill cost: ");
        subtotal = scanner.nextDouble();        

        // Perform calculations
        tax = computeTax(subtotal,taxRate);
        double t1 =(computeTax(subtotal, tipRate1));
        double t2 =(computeTax(subtotal, tipRate2));
        double t3 =(computeTax(subtotal, tipRate3));
        total = subtotal + computeTax(subtotal, taxRate);

        // Print receipt     
        //      =====================================
        //      Park Sushi
        //      Your server was: JULIE
        //      Subtotal: $56.23
        //      Tax: $2.81
        //      =====================================
        //      Total: $59.04
        //
        //      Suggested tips:
        //      10%: $5.90
        //      15%: $8.86
        //      20%: $11.81
        //
        //      Thank you!
        //      =====================================
        String st = "Suggested tips:";
        String ten ="10%: $";
        String fif ="15%: $";
        String twen ="20%: $";
        System.out.println("=====================================");
        System.out.println(restaurantName);
        System.out.println("Your server was: " + serverName.toUpperCase());
        System.out.println("Subtotal: $" + subtotal);
        System.out.printf("Tax: $%.2f\n" , tax);
        System.out.println("=====================================");
        System.out.printf("Total: $%.2f\n" , total);
        System.out.println("");
        System.out.println(st);
        System.out.print(ten);
        System.out.printf("%.2f\n" , t1);
        System.out.print(fif);
        System.out.printf("%.2f\n" , t2);
        System.out.print(twen);
        System.out.printf("%.2f\n" , t3);
        System.out.println("");
        System.out.println("Thank you!");

        System.out.println("=====================================");


    }

    //  Write a method to calculate the tax on the bill based on the subtotal and taxRate. Call the method and store the result in the variable tax. Here is the signature of the method:
    //  Calculate the total bill by adding the subtotal and tax together. Store the total bill in the variable total.
    //  Write a method to calculate the suggested tip, based on the total and the tip rate. Here is the signature of the method:
    public static double computeTax(double amount, double rate){
        double total = amount * rate;
        return total;
    }

}
这是我课程的评分结果

R8 Grade: 60 / 100

compileTest Score: 0 / 0
test1 Score: 10 / 10
test2 Score: 20 / 20
test3 Score: 10 / 10
test4 Score: 10 / 10
test5 Score: 10 / 10
test6 Score: 0 / 10
test7 Score: 0 / 10
test8 Score: 0 / 10
test9 Score: 0 / 10
---------------------------------------
GRADING DETAILS

grading based on file: R8.java

--------------------------------------------------------
TEST: compileTest CMD LINE: java R8Test 0 < input.txt


Your Output/Master Output:

R8.java compiled!                               R8.java compiled!

compileTest Score: 0 / 0
--------------------------------------------------------
TEST: test1 CMD LINE: java R8Test 1 < input.txt


Your Output/Master Output:

Alley Cat                                       Alley Cat

test1 Score: 10 / 10
--------------------------------------------------------
TEST: test2 CMD LINE: java R8Test 2 < input.txt


Your Output/Master Output:

Your server was: CONOR                          Your server was: CONOR

test2 Score: 20 / 20
--------------------------------------------------------
TEST: test3 CMD LINE: java R8Test 3 < input.txt


Your Output/Master Output:

Subtotal: $57.45                                Subtotal: $57.45

test3 Score: 10 / 10
--------------------------------------------------------
TEST: test4 CMD LINE: java R8Test 4 < input.txt


Your Output/Master Output:

Tax: $2.87                                      Tax: $2.87

test4 Score: 10 / 10
--------------------------------------------------------
TEST: test5 CMD LINE: java R8Test 5 < input.txt


Your Output/Master Output:

Total: $60.32                                   Total: $60.32

test5 Score: 10 / 10
--------------------------------------------------------
TEST: test6 CMD LINE: java R8Test 6 < input.txt


Your Output/Master Output:

10%: $5.75                                    | 10%: $6.03

test6 Score: 0 / 10
--------------------------------------------------------
TEST: test7 CMD LINE: java R8Test 7 < input.txt


Your Output/Master Output:

15%: $8.62                                    | 15%: $9.05

test7 Score: 0 / 10
--------------------------------------------------------
TEST: test8 CMD LINE: java R8Test 8 < input.txt


Your Output/Master Output:

20%: $11.49                                   | 20%: $12.06

test8 Score: 0 / 10
--------------------------------------------------------
TEST: test9 CMD LINE: java R8Test 9 < input.txt


Your Output/Master Output:

Alley Cat                                       Alley Cat
Your server was: CONOR                          Your server was: CONOR
Subtotal: $57.45                                Subtotal: $57.45
Tax: $2.87                                      Tax: $2.87
=====================================           =====================================
Total: $60.32                                   Total: $60.32

Suggested tips:                                 Suggested tips:
10%: $5.75                                    | 10%: $6.03
15%: $8.62                                    | 15%: $9.05
20%: $11.49                                   | 20%: $12.06

Thank you!                                      Thank you!
=====================================           =====================================
Number of lines: 14                             Number of lines: 14

test9 Score: 0 / 10
--------------------------------------------------------
R8等级:60/100
编译测试分数:0/0
测试1分数:10/10
测试2分数:20/20
测试3分数:10/10
测试4分数:10/10
测试5分数:10/10
测试6分数:0/10
测试7分数:0/10
测试8分数:0/10
测试9分数:0/10
---------------------------------------
分级细节
基于文件R8.java的分级
--------------------------------------------------------
测试:compileTest CMD行:java R8Test 0

请有人向我解释一下,我的程序中的什么导致我的程序将尖端舍入得比自动分级机输入到我的程序中的主输出更高。我找不到我的小费上涨的原因。我尝试了几种不同的方法,但都没有成功。

根据您代码中的示例,建议的小费是基于账单总额,但您是根据小计计算的。

您对小费四舍五入给出了哪些规则?非常感谢。愚蠢的错误。
    import java.util.Scanner;

public class R8 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        //      Read all the steps carefully before beginning. Understand the larger picture.
        //      Create a new Java Project named R8, and make a class named R8.
        //      Copy the following code and paste it inside the the curly braces of the main method:
        //      // Declare variables
        String restaurantName;
        String serverName;
        double subtotal;
        double tax = 0;
        double total = 0;
        double taxRate = 0.05;
        double tipRate1 = 0.10;
        double tipRate2 = 0.15;
        double tipRate3 = 0.20;

        //      // Ask and receive input from the user
        //      Create a Scanner object, prompt the user for the name of the restaurant, and read in their input to the variable restaurantName. The restaurant can be be more than one word, like "Park Sushi."
        Scanner scanner = new Scanner(System.in);
        System.out.print("name of the restaurant: ");
        restaurantName = scanner.nextLine();

        //      Prompt the user for the name of the server. Store the value in the variable serverName. Assume the server name will always be a first and last name, separated by one space character.
        System.out.print("server name: ");
        serverName = scanner.next();
        scanner.nextLine();

        //      Prompt the user for the cost of the bill. Store the value in the variable subtotal. Assume the cost will be a double value representing dollars, for example 56.23.
        System.out.print("Total bill cost: ");
        subtotal = scanner.nextDouble();        

        // Perform calculations
        tax = computeTax(subtotal,taxRate);
        double t1 =(computeTax(subtotal, tipRate1));
        double t2 =(computeTax(subtotal, tipRate2));
        double t3 =(computeTax(subtotal, tipRate3));
        total = subtotal + computeTax(subtotal, taxRate);

        // Print receipt     
        //      =====================================
        //      Park Sushi
        //      Your server was: JULIE
        //      Subtotal: $56.23
        //      Tax: $2.81
        //      =====================================
        //      Total: $59.04
        //
        //      Suggested tips:
        //      10%: $5.90
        //      15%: $8.86
        //      20%: $11.81
        //
        //      Thank you!
        //      =====================================
        String st = "Suggested tips:";
        String ten ="10%: $";
        String fif ="15%: $";
        String twen ="20%: $";
        System.out.println("=====================================");
        System.out.println(restaurantName);
        System.out.println("Your server was: " + serverName.toUpperCase());
        System.out.println("Subtotal: $" + subtotal);
        System.out.printf("Tax: $%.2f\n" , tax);
        System.out.println("=====================================");
        System.out.printf("Total: $%.2f\n" , total);
        System.out.println("");
        System.out.println(st);
        System.out.print(ten);
        System.out.printf("%.2f\n" , t1);
        System.out.print(fif);
        System.out.printf("%.2f\n" , t2);
        System.out.print(twen);
        System.out.printf("%.2f\n" , t3);
        System.out.println("");
        System.out.println("Thank you!");

        System.out.println("=====================================");


    }

    //  Write a method to calculate the tax on the bill based on the subtotal and taxRate. Call the method and store the result in the variable tax. Here is the signature of the method:
    //  Calculate the total bill by adding the subtotal and tax together. Store the total bill in the variable total.
    //  Write a method to calculate the suggested tip, based on the total and the tip rate. Here is the signature of the method:
    public static double computeTax(double amount, double rate){
        double total = amount * rate;
        return total;
    }

}