java - Why is my program rounding up wrong? -


here program calculate tax bill

someone please explain me in program causing program round tip higher master output inputed program auto grader. cannot find cause of tips coming through higher. ive tried several different things have been unsuccessful.

    import java.util.scanner;  public class r8 {      public static void main(string[] args) {         // todo auto-generated method stub         //      read steps before beginning. understand larger picture.         //      create new java project named r8, , make class named r8.         //      copy following code , paste inside the curly braces of 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 , receive input user         //      create scanner object, prompt user name of restaurant, , read in input variable restaurantname. restaurant can be more 1 word, "park sushi."         scanner scanner = new scanner(system.in);         system.out.print("name of restaurant: ");         restaurantname = scanner.nextline();          //      prompt user name of server. store value in variable servername. assume server name first , last name, separated 1 space character.         system.out.print("server name: ");         servername = scanner.next();         scanner.nextline();          //      prompt user cost of bill. store value in variable subtotal. assume cost double value representing dollars, 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         //      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 method calculate tax on bill based on subtotal , taxrate. call method , store result in variable tax. here signature of method:     //  calculate total bill adding subtotal , tax together. store total bill in variable total.     //  write method calculate suggested tip, based on total , tip rate. here signature of method:     public static double computetax(double amount, double rate){         double total = amount * rate;         return total;     }  } 

here graded results of program

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   output/master output:  r8.java compiled!                               r8.java compiled!  compiletest score: 0 / 0 -------------------------------------------------------- test: test1 cmd line: java r8test 1 < input.txt   output/master output:  alley cat                                       alley cat  test1 score: 10 / 10 -------------------------------------------------------- test: test2 cmd line: java r8test 2 < input.txt   output/master output:  server was: conor                          server was: conor  test2 score: 20 / 20 -------------------------------------------------------- test: test3 cmd line: java r8test 3 < input.txt   output/master output:  subtotal: $57.45                                subtotal: $57.45  test3 score: 10 / 10 -------------------------------------------------------- test: test4 cmd line: java r8test 4 < input.txt   output/master output:  tax: $2.87                                      tax: $2.87  test4 score: 10 / 10 -------------------------------------------------------- test: test5 cmd line: java r8test 5 < input.txt   output/master output:  total: $60.32                                   total: $60.32  test5 score: 10 / 10 -------------------------------------------------------- test: test6 cmd line: java r8test 6 < input.txt   output/master output:  10%: $5.75                                    | 10%: $6.03  test6 score: 0 / 10 -------------------------------------------------------- test: test7 cmd line: java r8test 7 < input.txt   output/master output:  15%: $8.62                                    | 15%: $9.05  test7 score: 0 / 10 -------------------------------------------------------- test: test8 cmd line: java r8test 8 < input.txt   output/master output:  20%: $11.49                                   | 20%: $12.06  test8 score: 0 / 10 -------------------------------------------------------- test: test9 cmd line: java r8test 9 < input.txt   output/master output:  alley cat                                       alley cat server was: conor                          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 -------------------------------------------------------- 

someone please explain me in program causing program round tip higher master output inputed program auto grader. cannot find cause of tips coming through higher. ive tried several different things have been unsuccessful.

given example in code, suggested tips based on total bill, calculating them on subtotal.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -