Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java: Would you kindly help with following assignment: FIX ME: Please explain the setter method in this example. I am very confused. This is all

Java: Would you kindly help with following assignment: FIX ME: Please explain the setter method in this example. I am very confused. This is all the information given. Thank you.

image text in transcribed

import java.util.Scanner;

public class IncomeTaxMain {

// 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 = " Enter 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.10, 0.20, 0.30, 0.40 };

// 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.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 + " Tax rate: " + taxRate + " Tax to pay: " + taxToPay);

// Get the next annual salary annualSalary = getInteger(scnr, PROMPT_SALARY); } } }

The program below uses a class, TaxTable Tools, 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 1. Modify the TaxTableTools class to use a setter method that accepts a new salary and tax rate table 2. Modify the program to call the new method, and run the program again, noting the same output. Note that the programs two classes are in separate tabs at the top The program below uses a class, TaxTable Tools, 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 1. Modify the TaxTableTools class to use a setter method that accepts a new salary and tax rate table 2. Modify the program to call the new method, and run the program again, noting the same output. Note that the programs two classes are in separate tabs at the top

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

25 Vba Macros For Data Analysis In Microsoft Excel

Authors: Klemens Nguyen

1st Edition

B0CNSXYMTC, 979-8868455629

More Books

Students also viewed these Databases questions