这是我从账单中计算税款的程序
有人请向我解释一下我的程序中的什么导致我的程序将尖端四舍五入高于自动评分器输入到我的程序中的主输出。我找不到我的提示通过更高的原因。我尝试了几种不同的方法,但都没有成功。
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
--------------------------------------------------------
有人请向我解释一下我的程序中的什么导致我的程序将尖端四舍五入高于自动评分器输入到我的程序中的主输出。我找不到我的提示通过更高的原因。我尝试了几种不同的方法,但都没有成功。