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

In the UML diagram above the super class Person has two sub classes : Student an

ID: 3741273 • Letter: I

Question

In the UML diagram above the super class Person has two sub classes : Student and Person. The instance variables and methods are as shown. All instance variables are of the type protected.

The student class overrides the calculateTax method as described in the Person class. In the person class this method return a tax value = 0.12*income . In the student class, this method returns a 0.0, as students are tax exempt.

The UML only shows constructors that take in one value of String , which is the SSN. However, feel free to add a default and full-arg constructor as needed .

Write the classes Person, Employee and Student. Also write a client class called TestPerson, that contains a menu driven program and that will do the following at the minimum,

1) Ask the user to enter the choice: 1 for Employee and 2 for Student.

2) If the choice is 1: create an Employee object and set all the instance variables. You need to get the SSN, email and salary from the user. Set the income to be equal to the salary. Output the values of each instance variable and display the tax amount, by calling the calculateTax method.

3) If the choice is 2: create a Student object and set all the instance variables. You need to get the SSN, Email and stipend from the user. Set income to be equal to the stipend. Output the values of each instance variable and display the tax amount by calling the calculateTax method.

Person # ssn: String Fincome: double #email. String +Person(String) +getincome0: double +getEmailString +setlncome(double):void +setEmail (String) void +calculateTax:double +getSSNO:String Student Employee + stipend: double +Student(String) +getStipend: double + setStipend(double): void +calculateTax:double + salary: double +Employee (String) +getSalary0: double +setSalary0.double

Explanation / Answer

TestPerson.java

import java.util.Scanner;

public class TestPerson{

public static void main(String[] args){

System.out.println("Enter the choice: 1 for Employee and 2 for Student");

Scanner in = new Scanner(System.in);

int choice = in.nextInt();

if(choice == 1) {

in.nextLine();

System.out.println("Enter the SSN");

String ssn = in.nextLine();

System.out.println("Enter the email");

String email = in.nextLine();

System.out.println("Enter the salary");

double salary = in.nextDouble();

Employee emp = new Employee(ssn, email, salary);

emp.setSalary(salary);

System.out.println(emp);

}

else {

in.nextLine();

System.out.println("Enter the SSN");

String ssn = in.nextLine();

System.out.println("Enter the email");

String email = in.nextLine();

System.out.println("Enter the stipend");

double stipend = in.nextDouble();

Student std = new Student(ssn, email, stipend);

std.setStipend(stipend);

System.out.println(std);

}

}

}

Person.java

public class Person{

protected String ssn, email;

protected double income;

public Person(String ssn, String email, double income) {

super();

this.ssn = ssn;

this.email = email;

this.income = income;

}

public String getSsn() {

return ssn;

}

@Override

public String toString() {

return "Person [ssn=" + ssn + ", email=" + email + ", income=" + income + "]";

}

public double getIncome() {

return income;

}

public double calculateTax() {

double totalincome = 0.12*income;

return totalincome;

}

public String getEmail() {

return email;

}

public void setEmail(String email) {

this.email = email;

}

public void setIncome(double income) {

this.income = income;

}

}

Employee.java

public class Employee extends Person {

protected double salary;

public Employee(String ssn, String email, double income) {

super(ssn, email, income);

}

public double getSalary() {

return salary;

}

public void setSalary(double salary) {

this.salary = salary;

}

@Override

public String toString() {

return "Employee [salary=" + salary + ", ssn=" + ssn + ", email=" + email + ", income=" + income + "]";

}

}

Student.java

public class Student extends Person{

protected double stipend;

@Override

public String toString() {

return "Student [stipend=" + stipend + ", ssn=" + ssn + ", email=" + email + ", income=" + income + "]";

}

public double getStipend() {

return stipend;

}

public void setStipend(double stipend) {

this.stipend = stipend;

}

public Student(String ssn, String email, double income) {

super(ssn, email, income);

}

public double calculateTax() {

return 0.0;

}

}

**Comment for any further queries.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote