In: Computer Science
this question has been answered incorrectly several times can someone answer it correctly and show me some examples of a run
Design and implement 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 email address.
A student has a class status (year 1,year 2,year 3,or year 4).
An employee has an office, salary, and date hired.
Use the Date class from JavaAPI 8 to create an object for 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.Design and implement all 5classes.
Write a test program that creates a Person,Student,Employee,Faculty, and Staff, and iinvokes their toString()methods
import java.util.*;
import java.lang.*;
// Person class
class Person{
String name;
String address;
int[] phone = new int[10];
String email;
Person(String name,String address,String email){ //
Person class constructor
this.name = name;
this.address = address;
this.email = email;
}
Person(String name,String address){
this.name = name;
this.address = address;
}
public String toString(){
return (name + " " + address + " "
+ email + " class : Person");
}
}
// Student class
class Student extends Person{
String year;
Student(String name,String address,String email){ //
Student class constructor
super(name,address);
this.email = email;
}
public String toString(){
return (name + " " + address + " "
+ email + " class : Student");
}
}
// Employee class
class Employee extends Person{
String office;
String salary;
String date;
Employee(String name,String address,String email){ //
Employee class constructor
super(name,address);
this.email = email;
}
Employee(String name,String address){
super(name,address);
}
public String toString(){
return (name + " " + address + " "
+ email + " class : Employee");
}
}
// Faculty class
class Faculty extends Employee{
String hour;
int rank;
Faculty(String name,String address,String email){ //
Faculty class constructor
super(name,address);
this.email = email;
}
public String toString(){
return (name + " " + address + " "
+ email + " class : Faculty");
}
}
// Staff class
class Staff extends Employee{
String title;
Staff(String name,String address,String email){ //
Staff class constructor
super(name,address);
this.email = email;
}
public String toString(){
return (name + " " + address + " "
+ email + " class : Staff");
}
}
public class Solution {
public static void main(String[] args){
Date d1 = new Date();
System.out.println("Current date is " + d1);
Person p = new Person("Adam","132KV
Station","adam"); // Make a person class object
Student s = new
Student("John","132KV Station","john"); // Make a student class
object
Employee e = new
Employee("Rocky","132KV Station","rocky"); // Make a student class
object
Faculty f = new
Faculty("Fira","132KV Station","fira"); // Make a faculty class
object
Staff o = new Staff("Ram","132KV
Station","ram"); // Make a staff class object
// Call toString method
System.out.println(p);
System.out.println(s);
System.out.println(e);
System.out.println(f);
System.out.println(o);
}
}
Output :