Question

a c++ program (The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person...

a c++ program (The Person, Student, Employee, Faculty, and Staff classes) 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 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. Use the MyDate classto create an object for date hired. A faculty member has office hours and a rank. A staff member has a title. Override the output() method in each class to display the class name and the person’s name. Draw the UML diagram for the classes and implement them. Write a test program that creates a Person, Student, Employee, Faculty, and Staff, and invokes their toString() methods.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

With no UML diagram I Have implemented the programme

Class #1 - Person.java:


public class Person {
public String name;
public String address;
public String phone;
public String email;

public Person(String name, String address, String phone, String email) {
this.name = name;
this.address = address;
this.phone = phone;
this.email = email;
}
@Override
public String toString() {
return this.getClass().getName() + "\n" + name;
}
}


Class #2 - Student.java:


public class Student extends Person {
// capitalize CLASS_STATUS variable is a typical Java convention
// for variables that have been declared as final (aka: constant)
public final String CLASS_STATUS;
public Student(String name, String address, String phone, String email, String classStatus) {
super(name, address, phone, email);
CLASS_STATUS = classStatus;
}
}


Class #3 - Employee.java:


public class Employee extends Person {
public String office;
public double salary;

public Employee(String name, String address, String phone, String email) {
super(name, address, phone, email);
}
}


Class #4 - Faculty.java:


public class Faculty extends Employee {
public String officeHours;
public int rank;

public Faculty(String name, String address, String phone, String email) {
super(name, address, phone, email);
}
}


Class #5 - Staff.java:


public class Staff extends Employee {
public String title;

public Staff(String name, String address, String phone, String email) {
super(name, address, phone, email);
}
}


Class #6 - TestPerson :


public class TestPerson {

public static void main(String[] args) {
Person person = new Person("John Doe", "123 Somewhere", "415-555-1212", "[email protected]");
Person student = new Student("Mary Jane", "555 School Street", "650-555-1212", "[email protected]", "junior");
Person employee = new Employee("Tom Jones", "777 B Street", "408-888-9999", "[email protected]");
Person faculty = new Faculty("Jill Johnson", "999 Park Ave", "925-222-3333", "[email protected]");
Person staff = new Staff("Jack I. Box", "21 Jump Street", "707-212-1112", "[email protected]");

System.out.println(person.toString() + "\n");
System.out.println(student.toString() + "\n");
System.out.println(employee.toString() + "\n");
System.out.println(faculty.toString() + "\n");
System.out.println(staff.toString() + "\n");
}
}



Output :

Person
John Doe

Student
Mary Jane

Employee
Tom Jones

Faculty
Jill Johnson

Staff
Jack I. Box

Add a comment
Know the answer?
Add Answer to:
a c++ program (The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT