Question: You need to implement a simple Java class named TaxCalculator to calculate tax of a person. This class should contain two instance variables: one String



You need to implement a simple Java class named TaxCalculator to calculate tax of a person. This class should contain two instance variables: one String variable to store the name and another double variable to store the income before tax. This class also provides the following public interface methods: - a constructor method TaxCalculator(String n, double i) with two input parameters n and i denoting the name and income respectively. - an accessor method getName() to return the name of the person - an accessor method getIncomeBefore Tax() to return the income of the person - a method getIncomeAfter Tax(double taxRate) to return the income after tax based on the input tax rate (the double input parameter named taxRate) - the static main() method to read the user inputs of person's name and income, create an instance of TaxCalculator, and then print (to console) the name, income before tax, and income after tax. Use the below starter code to implement the TaxCalculator class. Note: import necessary packages or class. /** TODO: the class specification */ public class TaxCalculator { private String name; private double income; * TODO: Complete the constructor method specification public TaxCalculator(String n, double i) { TODO: Complete the constructor method specification */ public Taxcalculator(String n, double i) { //TODO: complete the the code of the constructor method } 1* * The specification of the getName() method */ public string getName() { return name; } /* * TODO: the specification of the getIncomeBeforeTax() method */ public double getIncomeBeforeTax() { //TODO: complete the the code of the getIncomeBeforeTax method } /* * TODO: the specification of the getIncomeAfterTax() method */ public double getIncomeAfterTax(double taxRate) { //TODO: complete the the code of the getIncomeAfterTax method. Note: a sample taxRate is 0.3 } /* * TODO: Complete the code of the main method } /* * TODO: the specification of the getIncomeAfterTax() method public double getIncomeAfterTax(double taxRate) { //TODO: complete the the code of the getIncomeAfterTax method. Note: a sample taxRate is 0.3 } /* * TODO: Complete the code of the main method */ public static void main(String[] args) { //1. read user inputs of name, gross income, and tax rate Scanner users_input = new Scanner(System.in); System.out.print("Enter the name: "); String name = users_input.nextLine(); System.out.print("Enter the income: "); double income = users_input.nextDouble(); System.out.print("Enter the tax rate (e.g., 0.3): "); double tax rate = users_input.nextDouble(); users_input.close(); //2. TODO:create an instance of a TaxCalculator class with the input of name and gross income //3. TODO: print the name of the person 1/4. TODO: print the income before tax //5. TODO: print the income after tax } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
