Write Java program( see IncomeTaxClassTemplate) uses a class( TaxTableToolTemplate), 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 10000, 50000, 50001, 100001 and -1 (to end the program) and note the output tax rate and tax to pay.
a. Modify the TaxTableTools class to use a setter method that accepts a new salary and tax rate table.
b. Modify the program to call the new method, and run the program again, noting the same output.
Sample Input and Output:
Enter annual salary (-1 to exit):
100000
Annual Salary: 100000 Tax rate: 0.35 Tax to pay: 35000
Enter annual salary (-1 to exit):
200000
Annual Salary: 200000 Tax rate: 0.4 Tax to pay: 80000
Enter annual salary (-1 to exit):
-1
IncomeTaxClassTemplate
package Labs.Lab08;
import java.util.Scanner;
public class IncomeTaxClassTemplate {
// Method to prompt for and input an integer
public static int getInteger(Scanner input, String prompt) {
int inputValue;
System.out.println(prompt + ": ");
inputValue = input.nextInt();
return inputValue;
} //
//
***********************************************************************
public static void main (String [] args) {
final String PROMPT_SALARY = "\nEnter annual salary (-1 to exit)";
Scanner scnr = new Scanner(System.in);
int annualSalary;
double taxRate;
int taxToPay;
int i;
int [] salary = { 0, 20000, 50000, 100000,
Integer.MAX_VALUE };
double [] taxTable = { 0.0, 0.15, 0.25, 0.35,
0.40 };
// FIXME: Access the related class to declare a variable with an
instance of TaxTableTools class
// 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.setTables(salary, taxTable);
// Get the first annual salary to process
annualSalary = getInteger(scnr, PROMPT_SALARY);
while (annualSalary >= 0) {
taxRate = table.getValue(annualSalary);
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
annualSalary = getInteger(scnr, PROMPT_SALARY);
}
}
}
TaxTableToolsTemplate
package Labs.Lab08;
public class TaxTableToolsTemplate {
/**
* 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 = { 0, 20000, 50000, 100000,
Integer.MAX_VALUE };
private double[] value = { 0.0, 0.10, 0.20, 0.30, 0.40 };
private int nEntries;
//
***********************************************************************
// Default constructor
public TaxTableToolsTemplate() {
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 getValue(int searchArgument) {
double result;
boolean keepLooking;
int i;
result = 0.0;
keepLooking = true;
i = 0;
while ((i < nEntries) && keepLooking) {
if (searchArgument <= search[i]) {
result = value[i];
keepLooking = false;
} else {
++i;
}
}
return result;
}
}
If you have any doubts, please give me comment...
TaxTableTools.java
public 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 = { 0, 20000, 50000, 100000, Integer.MAX_VALUE };
private double[] value = { 0.0, 0.10, 0.20, 0.30, 0.40 };
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 void setTables(int salary[], double taxable[]){
this.search = salary;
this.value = taxable;
}
public double getValue(int searchArgument) {
double result;
boolean keepLooking;
int i;
result = 0.0;
keepLooking = true;
i = 0;
while ((i < nEntries) && keepLooking) {
if (searchArgument <= search[i]) {
result = value[i];
keepLooking = false;
} else {
++i;
}
}
return result;
}
}
IncomeTaxClass.java
import java.util.Scanner;
public class IncomeTaxClass {
// Method to prompt for and input an integer
public static int getInteger(Scanner input, String prompt) {
int inputValue;
System.out.println(prompt + ": ");
inputValue = input.nextInt();
return inputValue;
} //
public static void main(String[] args) {
final String PROMPT_SALARY = "\nEnter annual salary (-1 to exit)";
Scanner scnr = new Scanner(System.in);
int annualSalary;
double taxRate;
int taxToPay;
int i;
int[] salary = { 0, 20000, 50000, 100000, Integer.MAX_VALUE };
double[] taxTable = { 0.0, 0.15, 0.25, 0.35, 0.40 };
// FIXME: Access the related class to declare a variable with an instance of
// TaxTableTools 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.setTables(salary, taxTable);
table.setTables(salary, taxTable);
// Get the first annual salary to process
annualSalary = getInteger(scnr, PROMPT_SALARY);
while (annualSalary >= 0) {
taxRate = table.getValue(annualSalary);
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
annualSalary = getInteger(scnr, PROMPT_SALARY);
}
}
}

Write Java program( see IncomeTaxClassTemplate) uses a class( TaxTableToolTemplate), which has a tax table built in....
Write Java program ( see IncomeTaxOverloadClassTemplate) calculates a tax rate and tax to pay given an annual salary. The program uses a class,(see TaxTableToolsOverloadTemplate), which has the tax table built in. Run the program with annual salaries of 10000, 50000, 50001, 100001 and -1 (to end the program) and note the output tax rate and tax to pay. Overload the constructor. Add to the TaxTableTools class an overloaded constructor that accepts the base salary table and corresponding tax rate table...
The program calculates a tax rate and tax to pay given an annual salary. The program uses a class, TaxTableTools, which has the tax table built in. Run the program with annual salaries of 10000, 50000, 50001, 100001 and -1 (to end the program) and note the output tax rate and tax to pay. The output should be as follows: Enter annual salary (-1 to exit): 10000 Annual Salary: 10000 Tax rate: 0.1 Tax to pay: 1000 Enter annual salary...
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. Run the program below with annual salaries of 40000, 60000, and 0. Change the program to use a method to input the annual salary. Run the program again with the same annual salaries as above. Are results the same? This is the code including what I am...
1. Employees and overriding a class method The Java program (check below) utilizes a superclass named EmployeePerson (check below) and two derived classes, EmployeeManager (check below) and EmployeeStaff (check below), each of which extends the EmployeePerson class. The main program creates objects of type EmployeeManager and EmployeeStaff and prints those objects. Run the program, which prints manager data only using the EmployeePerson class' printInfo method. Modify the EmployeeStaff class to override the EmployeePerson class' printInfo method and print all the...
2. Given following Java program, convert to class diagram, create two instances of Employee, and initialize them with following values: For employee1, name – your friend’s name, salary = 30000, 8 hours and avail is false For employee2, name – your friend’s name, salary = 80000, 10 hours and avail is true public class Employee { private String name; private double salary ; private int hours ; private boolean avail ; public Employee (double r, double h, boolean hd) {...
in java PART ONE ======================================= Below is the "RetailItem" class definition that we used in Chapter 6. Write a "CashRegister" class that leverages this "RetailItem" class which simulates the sale of a retail item. It should have a constructor that accepts a "RetailItem" object as an argument. The constructor should also accept an integer that represents the quantity of items being purchased. Your class should have these methods: getSubtotal: returns the subtotal of the sale, which is quantity times price....
Task 3: Main Program Create a main program class that: Creates three or more Nurse instances assigned to different shifts. Creates three or more Doctor instances. Creates three or more Patient instances with pre-determined names and manually assigned physicians chosen from the pool of Doctor instances previously created. Generates another 20 Patient instances using randomly generated names and randomly assigns them physicians chosen from the pool of Doctor instances previously created. Prints the toString() values for all employees. Prints the...
Java Quadratic Probing Hash table HELP! Complete the Map and Entry class provided in Map.java. Create a tester/driver class to show the Map class is working as intended. Methods/Constructor correctly completed (2pt) This is the Map class methods Map(), put(key, value), get(key), isEmpty(), makeEmpty() Private class correctly completed (2pt) This is the Entry class methods Add the methods that are required for this to work correctly when stored in the QuadraticProbingHashTable Tester class (1pt) Show the methods of the Map...