Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Your objective is to write a simple java program that determines your tax liabil

ID: 3722397 • Letter: Y

Question

Your objective is to write a simple java program that determines your tax liability for the year.  

Your program must perform the following for one or more customers

: 1. Read the user’s first name and last name

2. Read 4 digit ID number. Use a loop to ensure customer has entered the correct ID number

3. Read the number of family members including you

4. Read the total income for the year

5. Calculate the taxable income

6. Determine the tax rate based on the criteria below

7. Calculate federal income tax

8. Output the input, given, and calculated values formatted as shown below

Taxable income = (Income -3200– 1000*number of family members)

Tax rate for taxable income less than $15000 is 5%, for taxable income between $15000 and $50000 tax rate is 15%, and for all other income the tax rate is 25%

Tax = taxable income * tax rate

Explanation / Answer

TaxCalculator .java

import java.util.Scanner;

public class TaxCalculator {

   private String name;
   private int idNumber;
   private double totalIncomeForThisYear;
   private int numberOfFamilyMembers;
  
   //Default constructor
   public TaxCalculator() {
      
   }

   public String getFirstName() {
       return name;
   }

   public void setFirstName(String firstName) {
       this.name = firstName;
   }

   public int getIdNumber() {
       return idNumber;
   }

   public void setIdNumber(int idNumber) {
       this.idNumber = idNumber;
   }

   public double getTotalIncomeForThisYear() {
       return totalIncomeForThisYear;
   }

   public void setTotalIncomeForThisYear(double totalIncomeForThisYear) {
       this.totalIncomeForThisYear = totalIncomeForThisYear;
   }

   public int getNumberOfFamilyMembers() {
       return numberOfFamilyMembers;
   }

   public void setNumberOfFamilyMembers(int numberOfFamilyMembers) {
       this.numberOfFamilyMembers = numberOfFamilyMembers;
   }

   // This method will be used to calculate TaxableIncome
   public double calculateTaxableIncome() {

       return (totalIncomeForThisYear-3200-1000*numberOfFamilyMembers);
   }
  
   // This method will be used to calculate tax rate
   public double calculateTaxRate() {

       double taxableIncome=calculateTaxableIncome();
       //based on taxable income tax rate will be determined
       if(taxableIncome<15000)
       {
           return 0.05;
       }
       else if(taxableIncome>15000 && taxableIncome<=50000)
       {
           return 0.15;
       }
       else if(taxableIncome>50000)
       {
           return 0.25;
       }
       return 0; //default
   }

   // This method will be used to calculate FederalTax
   public double calculateFederalTax() {

       return calculateTaxableIncome()*calculateTaxRate();
   }
  
   public void readData()
   {
       Scanner sc = new Scanner(System.in);
       System.out.println("Please enter the name : (Fisrt Name + last Name)");
       name = sc.nextLine();
       //To read Id
       while (true) { // Condition in while loop is always true here
           System.out.println("Please enter the 4 digit ID : ");
           idNumber = sc.nextInt();

           if (idNumber < 999) {
               System.out.println("Try again ! You entered a wrong input");
               continue;
           } else {
               break;
           }
       }
       System.out.println("Please enter total income for this year : ");
       totalIncomeForThisYear = sc.nextDouble();
      
       System.out.println("Please enter the number of family members : ");
       numberOfFamilyMembers = sc.nextInt();
   }
  
   public static void main(String[] args) {

       TaxCalculator calculator=new TaxCalculator();
       //read input
        calculator.readData();
      
        System.out.println("Total Taxable Income is $"+calculator.calculateTaxableIncome());
        System.out.println("Tax Rate is "+calculator.calculateTaxRate());
        System.out.println("Total Federal Tax is $"+calculator.calculateFederalTax());
   }
}

Output

Please enter the name : (Fisrt Name + last Name)
waseem akram
Please enter the 4 digit ID :
45
Try again ! You entered a wrong input
Please enter the 4 digit ID :
4521
Please enter total income for this year :
40000
Please enter the number of family members :
4
Total Taxable Income is $32800.0
Tax Rate is 0.15
Total Federal Tax is $4920.0