Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee.
(The Person, Student, Employee, Faculty, and Staff classes)
A person has a name, address, phone number, and email 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 a Person, Student, Employee, Faculty, and Staff, and invokes their toString() methods.
public class PersonDemo {
public static void main(String args[]) {
Person person = new Person("Daniel Dyson"), student = new Student("Charles Evans"),
employee = new Employee("Ethan Carter"), faculty = new Faculty("Harold Brooks"),
staff = new Staff("Connor Stevenson"), people[] = { person, student, employee, faculty, staff };
for (Person p : people)
System.out.println(p);
}
static class Person {
String name, address, phoneNumber, email;
Person(String n) {
name = n;
}
@Override
public String toString() {
return "Person " + name;
}
}
static class Student extends Person {
Student(String n) {
super(n);
}
enum Status {
freshman, sophomore, junior, senior
}
Status classStatus;
@Override
public String toString() {
return "Student " + name;
}
}
static class Employee extends Person {
Employee(String n) {
super(n);
}
String office, hireDate;
double salary;
@Override
public String toString() {
return "Employee " + name;
}
}
static class Faculty extends Employee {
Faculty(String n) {
super(n);
}
String officeHours, rank;
@Override
public String toString() {
return "Faculty " + name;
}
}
static class Staff extends Employee {
Staff(String n) {
super(n);
}
String title;
@Override
public String toString() {
return "Staff " + name;
}
}}
Comments
Leave a comment