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

***JAVA problem Tax Payer Your task is to implement a TaxPayer class with the fo

ID: 3675910 • Letter: #

Question

***JAVA problem

Tax Payer

Your task is to implement a TaxPayer class with the following attributes: the social security number (use a string for the type), the yearly gross income (double), and the tax owed (double).

The tax is 15% of income for incomes under $30000 and 28% for incomes that are $30000 or higher.

You can start with the following template:

Given a TaxPayer Y, the following methods should be defined:

A constructor that takes two parameters: social security number and gross income will be needed to instatiate a TaxPayer object. Then, the tax owed can be computed from these two given inputs.

Your implementation should meet the following additional criteria:

source file is named as TaxPayer.java

income and tax is printed to two decimal places.

Testing Your Implementation

The following program is a trivial example of how your class will be tested.

The output of the above program should look like this:

*Note

You only need to submit the TaxPayer.java (i.e. no main function) file. However, you should test it with a main program similar to the TestProgram.java above

Y.getGrossIncome() returns Y's gross income as a double Y.getTaxOwed() returns Y's tax owed as a double Y.print() prints Y's tax information (see example below).

Explanation / Answer


// TaxPayer.java

import java.text.DecimalFormat;

public class TaxPayer {
   private String ssn;
   private double grossIncome;
   private double taxOwed;
  
   public TaxPayer(String ssn, double grossIncome){
       this.ssn = ssn;
       this.grossIncome = grossIncome;
      
       // calculating taxOwed
       if(grossIncome < 30000){
           taxOwed = grossIncome*0.15;
       }else{
           taxOwed = grossIncome*0.28;
       }
   }
  
   public double getGrossIncome(){
       return grossIncome;
   }
   public double getTaxOwed(){
       return taxOwed;
   }
   public void print(){
       // to print 2 decimal precision
       DecimalFormat df = new DecimalFormat("#.00");
       System.out.println("SSN: "+ssn);
       System.out.println("Income: $"+df.format(grossIncome));
       System.out.println("Tax owed: $"+df.format(taxOwed));
   }

}
//Test Class

class TestProgram{
   public static void main(String[] args) {
       TaxPayer Smith = new TaxPayer("333333333", 30000.0);
       Smith.print();
   }
}


/*

output:

SSN: 333333333
Income: $30000.00
Tax owed: $8400.00

*/