Question: 6 . 2 3 Java example: Salary calculation with methods zyDE 6 . 2 3 . 1 : Calculate salary: Using methods. Separating calculations into

6.23 Java example: Salary calculation with methods
zyDE 6.23.1: Calculate salary: Using methods.
Separating calculations into methods simplifies modifying and expanding programs.
The following program calculates the tax rate and tax to pay, using methods. One method returns a tax rate based on an annual salary.
1. Run the program below with annual salaries of 40000,60000, and 0.
2. Change the program to use a method to input the annual salary.
3. Run the program again with the same annual salaries as above. Are results the same?
Note: The calculation is inaccurate to how taxes are formally assessed and is a simplification for educational purposes only.
```
Load default template...
38\/ FIXME: Change the input to come from a method
annualSalary = scnr.nextInt();
while (annualSalary >0){
taxRate = getCorrespondingTableValue(annualSalary, salaryBase, taxBase);
taxToPay=(int)(annualSalary * taxRate); // Truncate tax to an integer amount
System.out.println("Annual salary: "+ annualSalary +
"\tTax rate: "+ taxRate +
"\tTax to pay: "+ taxToPay);
// Get the next annual salary
// FIXME: Change the input to come from a method
System.out.println("
Enter annual salary (0 to exit): ");
annualSalary = scnr-nextInt();
}
57
40000600000
```
6 . 2 3 Java example: Salary calculation with

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!