Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

ions 11.5-1T.L 112 ( The Person, Student, Employee Faculty, and Staff classes cl

ID: 3859654 • Letter: I

Question

ions 11.5-1T.L 112 ( The Person, Student, Employee Faculty, and Staff classes class named Person and its two subclasses named Student and Make Faculty and Staff subclasses of Employee. A person address, phone number, and email address. A student has a class status (f sophomore, junior, or senior). Define the status as a constant. An emplo an office, salary, and date hired. Use the MyDate class def Exercise 10.14 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. Draw the UML diagram for the classes and implement them. Write gram that creates a Person, Student, Employee, Faculty, and Staff, and invokes their toStringO methods s) Design a ent and Employee. name has a eshman eshman ined in Programming diagram for the classes and implement them. Write a test pro-

Explanation / Answer

Person.java

public class Person {
   // Declaring variables
   private String name, address;

   // Zero Argument Constructor
   public Person() {
       super();
   }

   public Person(String name, String address) {
       super();
       this.name = name;
       this.address = address;
   }

   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;
   }

   @Override
   public String toString() {
       return "Person name=" + name + ", address=" + address ;
   }

}

_______________

Student.java

public class Student extends Person {

   private final String classStatus;

   public Student(String classStatus) {

       this.classStatus = classStatus;

   }

   public Student(String name, String address, String classStatus) {

       super(name, address);

       this.classStatus = classStatus;

   }

   public String toString() {

       return super.toString() + " Student " + this.classStatus;

   }

}

_________________

Employee.java

public class Employee extends Person {
   // Declaring variables
   private String office;
   private double salary;

   // Zero Argument Constructor
   public Employee() {
       super();
   }

   // Parameterized constructor.
   public Employee(String name, String address, String office, double salary) {
       super(name, address);
       this.office = office;
       this.salary = salary;
   }

   // Setters and getters
   public String getOffice() {
       return office;
   }

   public void setOffice(String office) {
       this.office = office;
   }

   public double getSalary() {
       return salary;
   }

   public void setSalary(double salary) {
       this.salary = salary;
   }

   // toString() method displays the contents of the object.
   @Override
   public String toString() {

       return super.toString() + " office=" + office + ", salary=" + salary;
   }

}

___________________

Staff.java

public class Staff extends Employee {
   //Declaring variables
private String title;

//Zero Argument Constructor
public Staff() {
   super();
}

//Parameterized constructor.
public Staff(String name, String address,String office, double salary,String title) {
   super(name,address,office,salary);
   this.title = title;
}

//Setters and getters
public String getTitle() {
   return title;
}

public void setTitle(String title) {
   this.title = title;
}

//toString() method displays the contents of the object.
@Override
public String toString() {

   return super.toString()+" Title=" + title;
}

}

_________________

Faculty.java

public class Faculty extends Employee {
   //Declaring variables
private int office_hours;

//Zero Argument Constructor
public Faculty() {
   super();
}

//Parameterized constructor.
public Faculty(String name, String address, String office, double salary,int office_hours) {
   super(name,address,office,salary);
   this.office_hours = office_hours;
}

//Setters and getters
public int getOffice_hours() {
   return office_hours;
}


public void setOffice_hours(int office_hours) {
   this.office_hours = office_hours;
}

//toString() method displays the contents of the object.
@Override
public String toString() {

   return super.toString()+" office_hours=" + office_hours ;
}


}

____________________

Driver.java

import java.util.ArrayList;

public class Driver {

   public static void main(String[] args) {
       /*
       //Creating the object of Employee Class
       Person person=new Person("Kane","101 Church Street","kane@gamil.com",991234568);
      
       //Displaying the Person Details
       System.out.println(person.toString());
      
       //Creating the object of Student Class
       Student s=new Student(0) ;
      
       //Displaying the Student Details
       System.out.println(s.toString());
      
       //Creating the date Class Object
       MyDate d=new MyDate(2016, 06, 31);
      
       //Creating the object of Employee Class
       Employee emp=new Employee("WIPRO", 50000, d);
      
       //Displaying the Employee Details
       System.out.println(emp.toString());
      
      
       //Creating the object of Faculty Class
       Faculty faculty=new Faculty(8, "Professor");
      
       //Displaying the Faculty Details
       System.out.println(faculty.toString());
      
       Staff staff=new Staff("Engineer");
       System.out.println(staff.toString());
      
*/
       ArrayList<Person> al=new ArrayList<Person>();
       al.add(new Student("James","101 Church Street","Sophomore"));
       al.add(new Student("Pattinson","44 That Street","Junior"));
       al.add(new Faculty("Williams","500 Over There Street","Accenture",50000,8));
       al.add(new Staff("Williams","867 Hay Street","Microsoft",80000,"Janitor"));
       for(int i=0;i<al.size();i++)
       {
           System.out.println(" "+al.get(i).toString());
       }
      
      
   }

}

____________________

Output:


Person name=James, address=101 Church Street Student Sophomore

Person name=Pattinson, address=44 That Street Student Junior

Person name=Williams, address=500 Over There Street office=Accenture, salary=50000.0 office_hours=8

Person name=Williams, address=867 Hay Street office=Microsoft, salary=80000.0 Title=Janitor

___________Thank You