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

Create a TaxReturn class with fields that hold a taxpayer’s Social Security numb

ID: 3683886 • Letter: C

Question

Create a TaxReturn class with fields that hold a taxpayer’s Social Security number, last name, first name, middle initial, zip code, annual income, marital status, number of vehicles owned, number of pets owned, and number of toasters owned. The StringBuilder class must be used in this Assignment. The program will calculate the tax liability based on annual income and the percentages in the following table:

Marital Status

Single

Married

25%

24%

50%

49%

75%

74%

Prompt the user to enter the data needed to output a summary of the information gathered. Make sure to ask for the information in the format you would like it from the user and adhere to the following:

If the Social Security number is not in the correct format, then reprompt for the information again

Marital status must be either ‘S’ or ‘s’ or ‘M’ or ‘m’

No negative incomes are allowed, so the value must be above zero

Data set 1 to input:

Social Security number 888-99-5623, last name Jones, first name Mkuy, middle initial L, zip code 12345, annual income 73564, marital status m, number of vehicles owned 5, number of pets owned 0, and number of toasters owned 9.

Data set 2 to input:

Social Security number 899-99-5624, last name Jim, first name Jane, middle initial P, zip code 12344, annual income 23564, marital status M, number of vehicles owned 1, number of pets owned 12, and number of toasters owned 2.

Data set 3 to input:

Social Security number 111-99-3324, last name Groske, first name Jenry, middle initial P, zip code 55544, annual income 123564, marital status s, number of vehicles owned 0, number of pets owned 2, and number of toasters owned 1.

Data set 4 to input:

Select your own values for this data set.

Marital Status

TOTAL Income in U.S. Dollars

Single

Married

0–15000

25%

24%

15001–49001

50%

49%

49002 and up

75%

74%

Explanation / Answer

import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

class TaxPayer {
   static Scanner reader = new Scanner(System.in); // Reading from System.in

   private String soc_serial_num;
   private String last_name;
   private String first_name;
   private String middle_initial;
   private int zip_code;
   private double annual_income;
   private String marital_status;
   private int no_vehicles;
   private int no_pets;
   private int no_toasters;
   private int tax_perc;

   public TaxPayer(String soc_serial_num, String last_name, String first_name,
           String middle_initial, int zip_code, double annual_income,
           String marital_status, int no_vehicles, int no_pets, int no_toasters) {
       super();
       this.soc_serial_num = soc_serial_num;
       this.last_name = last_name;
       this.first_name = first_name;
       this.middle_initial = middle_initial;
       this.zip_code = zip_code;
       this.annual_income = annual_income;
       this.marital_status = marital_status;
       this.no_vehicles = no_vehicles;
       this.no_pets = no_pets;
       this.no_toasters = no_toasters;

   }

   public TaxPayer() {
       // TODO Auto-generated constructor stub
   }

   public String getSoc_serial_num() {
       return soc_serial_num;
   }

   public void setSoc_serial_num(String soc_serial_num) {

       String regex = "^\d{3}-?\d{2}-?\d{4}$";
       Pattern r = Pattern.compile(regex);
       Matcher m = r.matcher(soc_serial_num);
       if (m.find()) {
           this.soc_serial_num = soc_serial_num;
       } else {
           System.out.println("Invalid Security Serial Num. Please provide in this format:XXX-XX-XXXX");
           System.out.println("Enter a Social Security number(XXX-XX-XXXX) : ");
           setSoc_serial_num(reader.next());
       }
   }

   public String getLast_name() {
       return last_name;
   }

   public void setLast_name(String last_name) {
       this.last_name = last_name;
   }

   public String getFirst_name() {
       return first_name;
   }

   public void setFirst_name(String first_name) {
       this.first_name = first_name;
   }

   public String getMiddle_initial() {
       return middle_initial;
   }

   public void setMiddle_initial(String middle_initial) {
       this.middle_initial = middle_initial;
   }

   public int getZip_code() {
       return zip_code;
   }

   public void setZip_code(int zip_code) {
       this.zip_code = zip_code;
   }

   public double getAnnual_income() {
       return annual_income;
   }

   public void setAnnual_income(double annual_income) {
       if (annual_income > 0) {
           this.annual_income = annual_income;
       } else {
           System.out.println("Income must be grreater than Zero");
           System.out.println("Re-enter your annual income : ");
           setAnnual_income(reader.nextDouble());
       }
   }

   public String getMarital_status() {
       return marital_status;
   }

   public void setMarital_status(String marital_status) {
       if (marital_status.toLowerCase().equals("s")|| marital_status.toLowerCase().equals("m")){
           this.marital_status = marital_status;
       }
       else {
           System.out.println("Wrong Input for Marital Status.");
           System.out.println("Re-enter you marital status ('s'/'S'-> Single and 'm'/'M'-> Married) : ");
           setMarital_status(reader.next());
       }
   }

   public int getNo_vehicles() {
       return no_vehicles;
   }

   public void setNo_vehicles(int no_vehicles) {
       this.no_vehicles = no_vehicles;
   }

   public int getNo_pets() {
       return no_pets;
   }

   public void setNo_pets(int no_pets) {
       this.no_pets = no_pets;
   }

   public int getNo_toasters() {
       return no_toasters;
   }

   public void setNo_toasters(int no_toasters) {
       this.no_toasters = no_toasters;
   }

   public int getTax_perc() {
       return tax_perc;
   }

   public void setTax_perc() {
       if (annual_income > 0 && annual_income < 15000) {
           if (marital_status.toLowerCase().equals("s")) {
               tax_perc = 25;
           } else {
               tax_perc = 24;
           }

       } else if (annual_income > 15001 && annual_income < 49001) {

           if (marital_status.toLowerCase().equals("s")) {
               tax_perc = 50;
           } else {
               tax_perc = 49;
           }

       } else if (annual_income > 49002) {

           if (marital_status.toLowerCase().equals("s")) {
               tax_perc = 75;
           } else {
               tax_perc = 74;
           }

       }  
       System.out.println("TAX PERC: "+tax_perc);

   }

   public double calculateTaxLiability() {
       double tax = (annual_income / 100) * tax_perc;
       return tax;

   }

   @Override
   public String toString() {
       return "TaxPayer [soc_serial_num=" + soc_serial_num + ", last_name="
               + last_name + ", first_name=" + first_name
               + ", middle_initial=" + middle_initial + ", zip_code="
               + zip_code + ", annual_income=" + annual_income
               + ", marital_status=" + marital_status + ", no_vehicles="
               + no_vehicles + ", no_pets=" + no_pets + ", no_toasters="
               + no_toasters + "]";
   }

}

public class TaxReturn {
   static Scanner reader = new Scanner(System.in); // Reading from System.in

   public static void main(String args[]) {

       TaxPayer payer1 = new TaxPayer();

       for (int i = 0; i < 5; i++) {
           System.out.println("Enter a Social Security number(XXX-XX-XXXX) : ");
           payer1.setSoc_serial_num(reader.next());
           System.out.println("Enter your last name : ");
           payer1.setLast_name(reader.next());

           System.out.println("Enter your first name : ");
           payer1.setFirst_name(reader.next());

           System.out.println("Enter your middle initial : ");
           payer1.setMiddle_initial(reader.next());

           System.out.println("Enter zip code : ");
           payer1.setZip_code(reader.nextInt());

           System.out.println("Enter your annual income : ");
           payer1.setAnnual_income(reader.nextDouble());

           System.out.println("Enter you marital status ('s'/'S'-> Single and 'm'/'M'-> Married) : ");
           payer1.setMarital_status(reader.next());

           System.out.println("Number of vehicles you own : ");
           payer1.setNo_vehicles(reader.nextInt());

           System.out.println("Number of pets you own : ");
           payer1.setNo_pets(reader.nextInt());

           System.out.println("Number of toasters you own : ");
           payer1.setNo_toasters(reader.nextInt());

           payer1.setTax_perc();

           System.out.println(payer1.toString());
           System.out.println("Tax Liability: "
                   + payer1.calculateTaxLiability());
       }
   }
}

==========O/P==========

Enter a Social Security number(XXX-XX-XXXX) :
344-00-0000
Enter your last name :
fh
Enter your first name :
hf
Enter your middle initial :
h
Enter zip code :
78464
Enter your annual income :
89000
Enter you marital status ('s'/'S'-> Single and 'm'/'M'-> Married) :
m
Number of vehicles you own :
8
Number of pets you own :
0
Number of toasters you own :
0
TAX PERC: 74
TaxPayer [soc_serial_num=344-00-0000, last_name=fh, first_name=hf, middle_initial=h, zip_code=78464, annual_income=89000.0, marital_status=m, no_vehicles=8, no_pets=0, no_toasters=0]
Tax Liability: 65860.0

Let me know if you have any queris.

I have imposed valdidation on marital status,income and social securiry number. And it will ask you 4 time for the user input .I have kept that part in loop.

Thanks.