In: Computer Science
Write a Java class called Person. The class should have the following fields: A field for the person’s name. A field for the person’s SSN. A field for the person’s taxable income. A (Boolean) field for the person’s marital status. The Person class should have a getter and setter for each field. The Person class should have a constructor that takes no parameters and sets the fields to the following values: The name field should be set to “unknown”. The SSN field should be set to “unknown”. The taxable income field should be set to 0. The marital status field should be set to false. Write a Driver class to implement a program that does the following: Prompts the user to enter information for a person. Creates a Person object and sets the fields to the entered information. Calculates the tax that person owes according to the table below. Prints out the person’s information along with the amount of tax owed. If your status is single and your taxable income is over But not over The tax is Of the amount over $0 $8,000 10% $0 $8,000 $32,000 $800 + 15% $8,000 $32,000 $4,400 + 25% $32,000 If your status is married and if the taxable income is over But not over The tax is Of the amount over $0 $16,000 10% $0 $16,000 $64,000 $1,600 + 15% $16,000 $64,000 $8,800 + 25% $64,000
import java.util.*;
class Person
{
String name,ssn;
int taxincome;
boolean stat;
Person()
{
this.name = "Unknown";
this.ssn = "Unknown";
this.taxincome = 0;
this.stat = false;
}
void setName(String s)
{
name = s;
}
String getName()
{
return name;
}
void setSsn(String s)
{
ssn= s;
}
String getSsn()
{
return ssn;
}
void setTaxableIncome(int t)
{
taxincome = t;
}
int getTaxableIncome()
{
return taxincome;
}
void setStatus(boolean b)
{
stat = b;
}
boolean getStatus()
{
return stat;
}
double calculateTax(int t,boolean b)
{
int tax=0;
if(b == false)
{
if(t>0 && t<=8000)
{
tax = (t/100)*10;
}
if(t>8000 && t<= 32000)
{
int x = t-8000;
tax = 800+(x/100)*15;
}
if(t>32000)
{
tax = 4400+((t-32000)/100)*25;
}
}
if(b == true)
{
if(t>0 && t<=16000)
{
tax = (t/100)*10;
}
if(t>16000 && t<=64000)
{
tax = 1600+((t-16000)/100)*15;
}
if(t>64000)
{
tax = 8800+((t-64000)/100)*25;
}
}
return tax;
}
}
class Main{
public static void main(String [] args)
{
String name,ssn;
int taxincome;
boolean stat;
Scanner in = new Scanner(System.in);
Person m1 = new Person();
System.out.println("Enter the name of person : ");
name = in.nextLine();
System.out.println("Enter the SSN of person : ");
ssn = in.nextLine();
System.out.println("Enter the taxable income of person : ");
taxincome = in.nextInt();
System.out.println("Enter the marital status of person : ");
System.out.println("Please enter the marital status in
true/false");
stat = in.nextBoolean();
m1.setName(name);
m1.setSsn(ssn);
m1.setTaxableIncome(taxincome);
m1.setStatus(stat);
System.out.println();
System.out.println("=====================================================================");
System.out.println();
System.out.println("Name of person : "+m1.getName());
System.out.println("SSN of person : "+m1.getSsn());
System.out.println("Taxable income of person is :
"+m1.getTaxableIncome());
System.out.println("Marital status of person is :
"+m1.getStatus());
System.out.println("Total tax amount is
:"+m1.calculateTax(taxincome,stat));
}
}