Problem: (The Person, Sruden, 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, date hired. Define a class named MyDate that contains the fields year, month, and day. A faculty member has office hours and a rank. A staff member has a title. Overridde the toString method in each class to display the class name and the person's name.
Draw the UML diagram for classes. Implement the classes. Write a tes program that creates a Person, Student, Employee, Faculty, and Staff, and invokes their toString() methods

I am having trouble overriding the toString method in each class, Can any one give me any clarfication? (And If you see any other problems i might have, please help, thanks) And am I using the Superclass correctly?

public class Person {

    private String name, address, phone, email;
    
    public Person(){
    }
    
    public Person(String name, String address, String phone, String email){
        this.name = name;
        this.address = address;
        this.phone = phone;
        this.email = email;
    }
    
    public String getName(){
        return name;
    }
    
    public void setName(String name){
        this.name = name;
    }
    
     public String getAddress(){
        return address;
    }
    
    public void setAddress(String address){
        this.address = address;
    }
    
    public String getPhone(){
        return phone;
    }
    
    public void setPhone(String phone){
        this.phone = phone;
    }
    
    public String getEmail(){
        return phone;
    }
    
    public void setEmail(String email){
        this.email = email;
    }
    
    @Override
    public String toString(){
        return getClass().getName() + "\n" + name;
    }
}
public class Student extends Person{

    private final String CLASS_STATUS;
    
    public Student(String name, String address, String phone, String email,String CLASS_STATUS){
        super(name, address, phone, email);
        this.CLASS_STATUS =CLASS_STATUS;
    }

    public String getClassStatus(){
        return CLASS_STATUS;
    }
}

What trouble are you facing? What error are you getting??

If you analyse the error closely then you might be able to debug.

What trouble are you facing? What error are you getting??

If you analyse the error closely then you might be able to debug.

I am not recieving any error but I don't know if I am following the directions right

It looks fine; however, you need to read your instruction carefully.

Design a class named Person and its two subclasses named Student and Employee.

and

Overridde the toString method in each class to display the class name and the person's name.

To me, it means that you need to override toString() method of Student & Employee. You need to override toString() method for Person, Student, and Employee. Because you use 'extend' the Person class for Employee & Student, you need to override the toString() of Student & Employee or you would get wrong info.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.