In: Computer Science
use eclipse
Develop the classes for the following requirements:
1. A class named Employee (general, for college)
2. A class named Instructor (more specific, for college)
3. A class named Staff (more specific, for college, HR officer, Marking staff)
Tasks:
1. Figure out the relationships among the classes;
2. Determine the abstract class, and the child classes;
3. For the abstract class, determine at least one abstract method;
4. Each class should at least two data members and one extra method;
5. Full implementation of all constructors, getters/setters and toString, and other methods;
6. Test your Java code and take screen shots
Here are the relationship details:
Employee Class will be abstract class with following members and abstract methods:
package university;
public abstract class Employee {
int employeeId;
String firstName;
String lastName;
int age;
abstract String getFirstName();
abstract String getLastName();
abstract int getEmployeeId();
abstract int getAge();
abstract void setEmployeeId(int employeeId);
abstract void setFirstName(String firstName) ;
abstract void setLastName(String lastName) ;
abstract void setAge(int age);
}
Staff Class will extend Employee Class and have following members and methods:
package university;
public class Staff extends Employee{
int staffId;
String staffType;
String department;
public Staff(){}
public Staff(int employeeId,
String firstName,
String lastName,
int age,String departmen, int staffId,String staffType){
this.employeeId=employeeId;
this.firstName=firstName;
this.lastName=lastName;
this.age=age;
this.department=departmen;
this.staffId=staffId;
this.staffType=staffType;
}
@Override
String getFirstName() {
return firstName;
}
@Override
String getLastName() {
return lastName;
}
@Override
int getEmployeeId() {
return employeeId;
}
@Override
int getAge() {
return age;
}
@Override
void setEmployeeId(int employeeId) {
this.employeeId=employeeId;
}
@Override
void setFirstName(String firstName) {
this.firstName=firstName;
}
@Override
void setLastName(String lastName) {
this.lastName=lastName;
}
@Override
void setAge(int age) {
this.age=age;
}
public int getStaffId() {
return staffId;
}
public void setStaffId(int staffId) {
this.staffId = staffId;
}
public String getStaffType() {
return staffType;
}
public void setStaffType(String staffType) {
this.staffType = staffType;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
@Override
public String toString(){
return "Staff Details:"
+ "\nFirst Name:"+firstName+
"\nLast Name:"+lastName+
"\nAge:"+age+
"\nEmployee ID:"+employeeId+
"\nStaff ID:"+staffId+
"\nStaff Type:"+staffType+
"\nDepartment:"+department;
}
}
Instructor class will extent Employee Class and have following members and methods:
package university;
public class Instructor extends Employee{
//To which department does instructor belongs
String department;
//Instructor Id(different from employee id)
int instructorId;
String instrcutorType;
public Instructor(){
}
public Instructor(int employeeId,
String firstName,
String lastName,
int age,String departmen, int instructorId){
this.employeeId=employeeId;
this.firstName=firstName;
this.lastName=lastName;
this.age=age;
this.department=departmen;
this.instructorId=instructorId;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public int getIntstructorId() {
return instructorId;
}
public void setIntstructorId(int instructorId) {
this.instructorId = instructorId;
}
@Override
String getFirstName() {
return firstName;
}
@Override
String getLastName() {
return lastName;
}
@Override
int getEmployeeId() {
return employeeId;
}
@Override
int getAge() {
return age;
}
@Override
void setEmployeeId(int employeeId) {
this.employeeId=employeeId;
}
@Override
void setFirstName(String firstName) {
this.firstName=firstName;
}
@Override
void setLastName(String lastName) {
this.lastName=lastName;
}
@Override
void setAge(int age) {
this.age=age;
}
public int getInstructorId() {
return instructorId;
}
public void setInstructorId(int instructorId) {
this.instructorId = instructorId;
}
public String getInstrcutorType() {
return instrcutorType;
}
public void setInstrcutorType(String instrcutorType) {
this.instrcutorType = instrcutorType;
}
@Override
public String toString(){
return "Instructor Details:\n"
+ "First Name:"+firstName+
"\nLast Name:"+lastName+
"\nAge:"+age+
"\nEmployee ID:"+employeeId+
"\nInstructor ID:"+instructorId+
"\nDepartment:"+department+
"\nInstructor Type:"+instrcutorType;
}
}
MainClass to test the code:
package university;
public class MainClass {
public static void main(String[] args) {
Staff staff=new Staff();
Staff staff2=new Staff();
Instructor instructor=new Instructor();
Instructor instructor2=new Instructor();
staff.setFirstName("John");
staff.setLastName("Carpenter");
staff.setAge(30);
staff.setEmployeeId(123);
staff.setStaffId(001);
staff.setDepartment("HR");
staff.setStaffType("HR officer");
staff2.setFirstName("William");
staff2.setLastName("Doffe");
staff2.setAge(35);
staff2.setEmployeeId(124);
staff2.setStaffId(002);
staff2.setDepartment("Marketing");
staff2.setStaffType(" Marking staff");
instructor.setFirstName("John");
instructor.setLastName("Carpenter");
instructor.setAge(30);
instructor.setEmployeeId(125);
instructor.setInstructorId(011);
instructor.setDepartment("Physics");
instructor.setInstrcutorType("Physics Lecturer");
instructor2.setFirstName("Steve");
instructor2.setLastName("Smith");
instructor2.setAge(30);
instructor2.setEmployeeId(126);
instructor2.setInstructorId(012);
instructor2.setDepartment("Physics");
instructor2.setInstrcutorType("Physics Lab Instructor");
System.out.println(staff.toString());
System.out.println("\n");
System.out.println(staff2.toString());
System.out.println("\n");
System.out.println(instructor.toString());
System.out.println("\n");
System.out.println(instructor2.toString());
}
}
Output:
Staff Details:
First Name:John
Last Name:Carpenter
Age:30
Employee ID:123
Staff ID:1
Staff Type:HR officer
Department:HR
Staff Details:
First Name:William
Last Name:Doffe
Age:35
Employee ID:124
Staff ID:2
Staff Type: Marking staff
Department:Marketing
Instructor Details:
First Name:John
Last Name:Carpenter
Age:30
Employee ID:125
Instructor ID:9
Department:Physics
Instructor Type:Physics Lecturer
Instructor Details:
First Name:Steve
Last Name:Smith
Age:30
Employee ID:126
Instructor ID:10
Department:Physics
Instructor Type:Physics Lab Instructor
Screenshot of output: