Create a TaxReturn class with fields that hold a taxpayers S

Create a TaxReturn class with fields that hold a taxpayer\'s Social Security number, last name, first name, street address, city, state, zip code, annual income, marital status, and tax liability. Include a constructor that requires arguments that provide values for all the fields other than the tax liability. The constructor calculates the tax liability based on annual income and the percentages in the following table. In the TaxReturn class, also include a display method that displays all the TaxReturn data. Save the file as TaxReturn.java. Create an application that prompts a user for the data needed to create a TaxReturn. Continue to prompt the user for data as long as any of the following are true: The Social Security number is not in the correct format, with digits and dashes in the appropriate positions; for example, 999-99-9999. The zip code is not five digits. The marital status does not begin with one of the following: \"S\" \"s\", \"M\", or \"m\". The annual income is negative. After all the input data is correct, create a TaxReturn object and then display its values. Save the file as PrepareTax.java.

Solution



//TaxReturn.java

class TaxReturn
{
String SSN;
String lastname;
String firstName;
String streetAddress;
String city;
String state;
String zipcode;
double annualIncome;
String maritalStatus;
double taxliability;
public TaxReturn(String ssn, String last, String first, String st, String cit, String stat, String zip,double income, String marital)
{
this.SSN=ssn;
this.lastname=last;
this.firstName=first;
this.streetAddress=st;
this.city=cit;
this.state=stat;
this.zipcode=zip;
this.annualIncome=income;
this.maritalStatus=marital;
}
  
void calculateTax()
{
if(annualIncome>0 &&annualIncome<=20000 )
{
if(this.maritalStatus.equalsIgnoreCase(\"Single\"))
{
taxliability=this.annualIncome*15/100;
}
else
{
taxliability=this.annualIncome*14/100;
}
}
else if(annualIncome>=20001 &&annualIncome<=50000 )
{
if(this.maritalStatus.equalsIgnoreCase(\"Single\"))
{
taxliability=this.annualIncome*22/100;
}
else
{
taxliability=this.annualIncome*20/100;
}
}   
else if(annualIncome>=50001)
{
if(this.maritalStatus.equalsIgnoreCase(\"Single\"))
{
taxliability=this.annualIncome*30/100;
}
else
{
taxliability=this.annualIncome*28/100;
}
}
}
public void display()
{
System.out.println(\"Social Security Number: \"+this.SSN);
System.out.println(\"Last Name: \"+this.lastname);
System.out.println(\"First Name: \"+this.firstName);
System.out.println(\"Street address: \"+this.streetAddress);
System.out.println(\"City: \"+this.city);
System.out.println(\"State: \"+this.state);
System.out.println(\"Zipcode: \"+this.zipcode);
System.out.println(\"Annual Income: \"+this.annualIncome);
System.out.println(\"Marital Status: \"+this.maritalStatus);
System.out.println(\"Tax liability: \"+this.taxliability);
}
}

////////////////////////////////////////////////////////////////////////////////////


package preparetax;

////////////////////////////////////////////////////////////////////////////////////
//PrepareTax.java

import java.util.Scanner;
public class PrepareTax {

public static void main(String[] args) {
Scanner input=new Scanner(System.in);
String ssn=\"\";
int flag=0;
while(flag==0){
System.out.println(\"Enter Social Security Number: \");
ssn=input.nextLine();
if(ssn.length()==11 && ssn.charAt(3)==\'-\' && ssn.charAt(6)==\'-\')
{
flag=1;
break;
}
else
{
System.out.println(\"Social Security Number should be in the form of 999-99-9999 \");
}
}

System.out.println(\"Last Name: \");
String last=input.nextLine();
System.out.println(\"First Name: \");
String first=input.nextLine();
System.out.println(\"Street address: \");
String st=input.nextLine();
System.out.println(\"City: \");
String cit=input.nextLine();
System.out.println(\"State: \");
String stat=input.nextLine();

flag=0;
String zip=\"\";
while(flag==0){
System.out.println(\"Enter the Zipcode: \");
zip=input.nextLine();
if(zip.length()==5)
{
flag=1;
break;
}
else
{
System.out.println(\"Zipcode length must be five\");
}
}

flag=0;
double income=0;
while(flag==0){
System.out.println(\"Enter Annual Income: \");
income=input.nextDouble();
if(income>0)
{
flag=1;
break;
}
else
{
System.out.println(\"Annual income should be greater than zero\");
}
}
System.out.println(\"Marital Status: \");
String marital=input.nextLine();

TaxReturn taxReturn=new TaxReturn(ssn,last,first,st,cit,stat,zip,income,marital);
taxReturn.calculateTax();
taxReturn.display();
}
  
}

 Create a TaxReturn class with fields that hold a taxpayer\'s Social Security number, last name, first name, street address, city, state, zip code, annual incom
 Create a TaxReturn class with fields that hold a taxpayer\'s Social Security number, last name, first name, street address, city, state, zip code, annual incom
 Create a TaxReturn class with fields that hold a taxpayer\'s Social Security number, last name, first name, street address, city, state, zip code, annual incom

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site