In: Computer Science
Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name, address, phone number, and e-mail address. A student has a class status (freshman, sophomore, junior, or senior). Define the status as a constant. An employee has an office, salary, and date hired. A faculty member has office hours and a rank. A staff member has a title. Override the toString method in each class to display the class name and the person’s name.
Write a test program that creates objects of Person, Student, Employee, Faculty, and Staff, and invoke their toString() methods.
class Person
{
String name;
String address;
String phonenumber;
String email;
Person(String name, String address, String
phonenumber, String email)
{
this.name = name;
this.address = address;
this.phonenumber =
phonenumber;
this.email = email;
}
public String toString()
{
System.out.println("class name:
Person");
System.out.println("Details");
return
"name:\t"+this.name+"\naddress:\t"+this.address+"\nphone
number:\t"+this.phonenumber+"\nemail:\t"+this.email;
}
}
class Student extends Person
{
final String status;
Student(String name, String address, String
phonenumber, String email, String status)
{
super(name, address, phonenumber,
email);
this.status = status;
}
public String toString()
{
System.out.println("class name:
Student");
System.out.println("Details");
return
"name:\t"+this.name+"\naddress:\t"+this.address+"\nphone
number:\t"+this.phonenumber+"\nemail:\t"+this.email+"\nstatus:\t"+this.status;
}
}
class Employee extends Person
{
String office;
double salary;
String date;
Employee(String name, String address, String
phonenumber, String email, String office, double salary, String
date)
{
super(name, address, phonenumber,
email);
this.office = office;
this.salary = salary;
this.date = date;
}
public String toString()
{
System.out.println("class name:
Employee");
System.out.println("Details");
return
"name:\t"+this.name+"\naddress:\t"+this.address+"\nphone
number:\t"+this.phonenumber+"\nemail:\t"+this.email+"\noffice:\t"+this.office+"\nsalary:\t"+this.salary+"\ndate:\t"+this.date;
}
}
class Faculty extends Employee
{
int officehours;
int rank;
Faculty(String name, String address, String
phonenumber, String email, String office, double salary, String
date, int officehours, int rank)
{
super(name, address, phonenumber,
email, office, salary, date);
this.officehours =
officehours;
this.rank = rank;
}
public String toString()
{
System.out.println("class name:
Faculty");
System.out.println("Details");
return
"name:\t"+this.name+"\naddress:\t"+this.address+"\nphone
number:\t"+this.phonenumber+"\nemail:\t"+this.email+"\noffice
hours:\t"+this.officehours+"\nrank\t"+this.rank;
}
}
class Staff extends Employee
{
String title;
Staff(String name, String address, String phonenumber,
String email, String office, double salary, String date, String
title)
{
super(name, address, phonenumber,
email, office, salary, date);
this.title = title;
}
public String toString()
{
System.out.println("class name:
Staff");
System.out.println("Details");
return
"name:\t"+this.name+"\naddress:\t"+this.address+"\nphone
number:\t"+this.phonenumber+"\nemail:\t"+this.email+"\ntitle:\t"+this.title;
}
}
public class Test
{
public static void main(String args[])
{
Person person1 = new
Person("person1", "address1","5566777544","person1email");
System.out.println(person1.toString());
Person student1 = new
Student("student1", "address2","55667897544","student1@gm.com",
"junior");
System.out.println(student1.toString());
Person employee1 = new
Employee("employee1", "address3","5578667544","employee1email",
"banglore", 100000,"01-08-1019");
System.out.println(employee1.toString());
Person faculty1 = new
Faculty("faculty1", "address4","6977987544","faculty1email",
"banglore", 500000, "01-06-2018", 5, 3);
System.out.println(faculty1.toString());
Person staff1 = new Staff("staff1",
"address5","75869695984","staff1email", "banglore", 500000,
"01-06-2018", "title1");
System.out.println(staff1.toString());
}
}
If you have any doubts please comment and please don't dislike.