Question: The program below uses a class, TaxTableTools, which has a tax table built in . The main method prompts for a salary, then uses a
The program below uses a class, TaxTableTools, which has a tax table built in The main method prompts for a salary, then uses a TaxTableTools method to get the tax rate. The program then calculates the tax to pay and displays the results to the user. Run the program with annual salaries of and to end the program and note the output tax rate and tax to pay.
Modify the TaxTableTools class to use a setter method that accepts a new salary and tax rate table.
Modify the program to call the new method, and run the program again, noting the same output.
Notepublic class TaxTableTools
This class searches the 'search' table with a search argument and
returns the corresponding value in the 'value' table. Variable
'nEntries' has the number of entries in each table.
private int search Integer.MAXVALUE ;
private double value ;
private int nEntries;
Default constructor
public TaxTableTools
nEntries search.length; Set the length of the search table
FIXME: Write a void setter method that sets new values for the private
search and value tables. Name the method: setTables
The method receives as parameters tables from which to load the
search and value tables.
Method to get a value from one table based on a range in the other table
public double getValueint searchArgument
double result;
boolean keepLooking;
int i;
result ;
keepLooking true;
i ;
while i nEntries && keepLooking
if searchArgument searchi
result valuei;
keepLooking false;
else
i;
return result;
import java.util.Scanner;
public class IncomeTaxMain
Method to prompt for and input an integer
public static int getIntegerScanner input, String prompt
int inputValue;
System.out.printlnprompt : ;
inputValue input.nextInt;
return inputValue;
public static void mainString args
final String PROMPTSALARY
Enter annual salary to exit;
Scanner scnr new ScannerSystemin;
int annualSalary;
double taxRate;
int taxToPay;
int i;
int salary Integer.MAXVALUE ;
double taxTable ;
Access the related class
TaxTableTools table new TaxTableTools;
FIXME: Call a setter method in the TaxTableClass that supplies new
tables for the class to work with. The method should be called
with: table.setTablessalary taxTable;
Get the first annual salary to process
annualSalary getIntegerscnr PROMPTSALARY;
while annualSalary
taxRate table.getValueannualSalary;
taxToPayintannualSalary taxRate; Truncate tax to an integer amount
System.out.printlnAnnual Salary: annualSalary
tTax rate: taxRate
tTax to pay: taxToPay;
Get the next annual salary
annualSalary getIntegerscnr PROMPTSALARY;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
