java - How can I use computeTax method to calculate tax a variable defined in main and then call the value of tax later in main? -


how can use computetax method calculate tax variable defined in main , call value of tax later in main? further assistance appreciated on of code see below well.

import java.util.scanner;  // date: sep 29, 2015   public class r8 {      public static void main(string[] args) { //      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;         double total;         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.println("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.println("server name: ");         servername = scanner.nextline();  //      prompt user cost of bill. store value in variable subtotal. assume cost double value representing dollars, example 56.23.         system.out.println("total bill cost: ");         subtotal = scanner.nextdouble();         

i haven't preformed calculations yet

    // perform calculations 

my output code

    // 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! //              =====================================         system.out.println("=====================================");         system.out.println(restaurantname);         system.out.println("your server was: " + servername.touppercase());         system.out.println("subtotal: $" + subtotal);         system.out.println(tax);         system.out.println("=====================================");         system.out.println("total: $/n" + total);         system.out.println("suggested tips:");         system.out.println("10%: " + tiprate1);         system.out.println("15%: " + tiprate2);         system.out.println("20%: /n" + tiprate3);         system.out.println("thank you!");          system.out.println("=====================================");     } 

compute tax method have use calculate.

//  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){         tax = amount + rate         return tax;     }  } 

you need associate return value of method computetax local variable tax.

in main method:

tax = computetax(subtotal, taxrate); 

and method computetax calculate tax.

private static double computetax(double amount, double rate) {     return amount * rate; } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -