Question

In: Computer Science

Write a Java class called Person. The class should have the following fields: A field for...

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

Solutions

Expert Solution

  • Code for above problem -

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));
}
}

  • Screenshots of code -

  • Screenshots of output covering all input cases -


Related Solutions

Write a java class called circle that represents a circle. It should have following three fields:...
Write a java class called circle that represents a circle. It should have following three fields: int x (x-coordinate), int y (y-coordinate), double radius (radius of the circle). Your circle object should have following methods: public int getRadius () public int getX () public int getY () public double area () public double perimeter() public String toString() write a client program called CircleClient that creates objects of the circle class called c1 and c2. Assign values to the fields when...
Java - Write an abstract class called Shape with a string data field called colour. Write...
Java - Write an abstract class called Shape with a string data field called colour. Write a getter and setter for colour. Write a constructor that takes colour as the only argument. Write an abstract method called getArea()
Design a class named Pet, which should have the following fields: Name – The name field...
Design a class named Pet, which should have the following fields: Name – The name field holds the name of a pet. Type – The type field holds the type of animal that is the pet. Example values are “Dog”, “Cat”, and “Bird”. Age – The age field holds the pet’s age. The Pet class should also have the following methods: setName – The setName method stores a value in the name field. setType – The setType method stores a...
(java) Write a class called CoinFlip. The class should have two instance variables: an int named...
(java) Write a class called CoinFlip. The class should have two instance variables: an int named coin and an object of the class Random called r. Coin will have a value of 0 or 1 (corresponding to heads or tails respectively). The constructor should take a single parameter, an int that indicates whether the coin is currently heads (0) or tails (1). There is no need to error check the input. The constructor should initialize the coin instance variable to...
(In java language) Write an abstract class called House. The class should have type (mobile, multi-level,...
(In java language) Write an abstract class called House. The class should have type (mobile, multi-level, cottage, etc.) and size. Provide the following methods: A no-arg/default constructor. A constructor that accepts parameters. A constructor that accepts the type of the house and sets the size to 100. All other required methods. An abstract method for calculating heating cost. Come up with another abstract method of your own. Then write 2 subclasses, one for mobile house and one for cottage. Add...
JAVA Specify, design, and implement a class called PayCalculator. The class should have at least the...
JAVA Specify, design, and implement a class called PayCalculator. The class should have at least the following instance variables: employee’s name reportID: this should be unique. The first reportID must have a value of 1000 and for each new reportID you should increment by 10. hourly wage Include a suitable collection of constructors, mutator methods, accessor methods, and toString method. Also, add methods to perform the following tasks: Compute yearly salary - both the gross pay and net pay Increase...
In C++ Define a base class called Person. The class should have two data members to...
In C++ Define a base class called Person. The class should have two data members to hold the first name and last name of a person, both of type string. The Person class will have a default constructor to initialize both data members to empty strings, a constructor to accept two string parameters and use them to initialize the first and last name, and a copy constructor. Also include appropriate accessor and mutator member functions. Overload the operators == and...
a) Design a Java Class which represents a Retail Item. It is to have the following fields
 a) Design a Java Class which represents a Retail Item. It is to have the following fields Item Name Item Serial No Item Unit Price Item Stock Level Item Reorder Level It is to have at least the following methods an Observer, Mutator and a Display method for each field. It is also to have a buy and a restock method and a method to issue a warning if the stock level goes below the re-order level. b) Extend the Retail Item class of part a) above...
a) Design a Java Class which represents a Retail Item. It is to have the following fields
 a) Design a Java Class which represents a Retail Item. It is to have the following fields  Item Name  Item Serial No  Item Unit Price  Item Stock Level  Item Reorder Level  It is to have at least the following methods an Observer, Mutator and a Display method for each field. It is also to have a buy and a restock method and a method to issue a warning if the stock level goes below the re-order level.    b) Extend...
Suppose we have a Java class called Person.java public class Person { private String name; private...
Suppose we have a Java class called Person.java public class Person { private String name; private int age; public Person(String name, int age) { this.name = name; this.age = age; } public String getName(){return name;} public int getAge(){return age;} } (a) In the following main method which lines contain reflection calls? import java.lang.reflect.Field; public class TestPerson { public static void main(String args[]) throws Exception { Person person = new Person("Peter", 20); Field field = person.getClass().getDeclaredField("name"); field.setAccessible(true); field.set(person, "Paul"); } }...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT