0.USE FACTORY METHOD DESIGN 1. Implement an interface called EmployeeInfo with t
ID: 3597302 • Letter: 0
Question
0.USE FACTORY METHOD DESIGN
1. Implement an interface called EmployeeInfo with the following constant variables:
FACULTY_MONTHLY_SALARY = 6000.00
STAFF_MONTHLY_HOURS_WORKED = 160
2. Implement an abstract class Employee with the following requirements:
Attributes
last name (String)
first name (String)
ID number (String)
Sex - M or F
Birth date - Use the Calendar Java class to create a date object
Default argument constructor and argument constructors.
Public methods
toString - returning a string with the following format:
ID Employee number :_________
Employee name: __________
Birth date: _______
mutators and accessors
abstract method monthlyEarning that returns the monthly earning.
3. Implement a class called Staff extending from the class Employee with the following requirements:
Attribute
Hourly rate
Default argument and argument contructors
Public methods
get and set
The method monthlyEarning returns monthly salary (hourly rate times 160)
toString - returning a string with the following format:
ID Employee number :_________
Employee name: __________
Birth date: _______
Full Time
Monthly Salary: _________
Implelment a class Education with the following requirements:
Attributes
Degree (MS or PhD )
Major (Engineering, Chemistry, English, etc ... )
Research (number of researches)
Default argument and argument constructors.
Public methods
get and set
Implement a class Faculty extending from the class Employee with the following requirements:
Attributes
Level (Use enum Java)
"AS": assistant professor
"AO": associate professor
"FU": professor
Education object
Default argument and argument constructor
Public methods
mutators and accessors
The method monthlyEarning returns monthly salary based on the faculty's level.
AS - faculty monthly salary
AO - 1.5 times faculty monthly salary
FU - 2.0 times faculty monthly salary
toString - returning a string with the following format:
ID Employee number :_________
Employee name: __________
Birth date: _______
XXXXX Professor where XXXXX can be Assistant, Associate or Full
Monthly Salary: _________
Implement a class called Partime extending from the class Staff with the following requirements:
Attributes
Hours worked per week
Default argument and argument constructors
Public methods
mutators and accessors
The method monthlyEarning returns monthly salary . The monthly salary is equal to hourly rate times the hours worked in four weeks.
toString - returning a string with the following format:
ID Employee number :_________
Employee name: __________
Birth date: _______
Hours works per month: ______
Monthly Salary: _________
mplement a test driver program that creates a one-dimensional array of class Employee to store the objects Staff, Faculty and Partime.
Using polymorphism, display the following outputs:
a. Employee information using the method toString
Staff
Faculty
Part-time
b. Total monthly salary for all the part-time staff .
c. Total monthly salary for all employees.
d. Display all employee information descending by employee id using interface Comparable
e. Display all employee information ascending by last name using interface Comparer
f. Duplicate a faculty object using clone. Verify the duplication.
Test Data
Staff
Last name: Allen
First name: Paita
ID: 123
Sex: M
Birth date: 2/23/59
Hourly rate: $50.00
Last name: Zapata
First Name: Steven
ID: 456
Sex: F
Birth date: 7/12/64
Hourly rate: $35.00
Last name:Rios
First name:Enrique
ID: 789
Sex: M
Birth date: 6/2/70
Hourly rate: $40.00
Faculty
Last name: Johnson
First name: Anne
ID: 243
Sex: F
Birth date: 4/27/62
Level: Full
Degree: Ph.D
Major: Engineering
Reseach: 3
Last name: Bouris
First name: William
ID: 791
Sex: F
Birth date: 3/14/75
Level: Associate
Degree: Ph.D
Major: English
Reseach: 1
Last name: Andrade
First name: Christopher
ID: 623
Sex: F
Birth date: 5/22/80
Level: Assistant
Degree: MS
Major: Physical Education
Research: 0
Part-time
Last name: Guzman
First name: Augusto
ID: 455
Sex: F
Birth date: 8/10/77
Hourly rate: $35.00
Hours worked per week: 30
Last name: Depirro
First name: Martin
ID: 678
Sex: F
Birth date: 9/15/87
Hourly rate: $30.00
Hours worked per week:15
Last name: Aldaco
First name: Marque
ID: 945
Sex: M
Birth date: 11/24/88
Hourly rate: $20.00
Hours worked per week: 35
Explanation / Answer
//EmployeeInfo.java
package emp;
public interface EmployeeInfo {
double FACULTY_MONTHLY_SALARY = 6000.00;
int STAFF_MONTHLY_HOURS_WORKED = 160;
}
//Employee.java
package emp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public abstract class Employee {
private String lastName;
private String firstName;
private String idNumber;
private char sex;
private Date birthDate;
public Employee() {
}
public Employee(String lastName, String firstName, String idNumber, char sex, String birthDate) {
super();
this.lastName = lastName;
this.firstName = firstName;
this.idNumber = idNumber;
this.sex = sex;
//create an instance of SimpleDateFormat
//MM: month (2 digits)
//dd: day (2 digits)
//yyyy: year (four digits)
//more of this in the javadoc
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
//parse the String as a Date
Date desiredDate=null;
try {
desiredDate = sdf.parse(birthDate);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/*//Calendar.getInstance() should return a GregorianCalendar instance by "default"
Calendar calendar = Calendar.getInstance();
//setting the date into the Calendar
calendar.setTime(desiredDate);*/
this.birthDate =desiredDate;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getIdNumber() {
return idNumber;
}
public void setIdNumber(String idNumber) {
this.idNumber = idNumber;
}
public char getSex() {
return sex;
}
public void setSex(char sex) {
this.sex = sex;
}
public Date getBirthDate() {
return birthDate;
}
public void setBirthDate(Date birthDate) {
this.birthDate = birthDate;
}
@Override
public String toString() {
return "Employee idNumber=" + idNumber + " Employee Name : "+firstName+" "+lastName+" birthDate=" + birthDate + "]";
}
abstract double monthlyEarning();
}
//Staff.java
package emp;
import java.util.Date;
public class Staff extends Employee implements EmployeeInfo {
private double hourlyRate;
public Staff() {
super();
}
public Staff(String lastName, String firstName, String idNumber, char sex, String birthDate) {
super(lastName, firstName, idNumber, sex, birthDate);
}
public double getHourlyRate() {
return hourlyRate;
}
public void setHourlyRate(double hourlyRate) {
this.hourlyRate = hourlyRate;
}
public Staff(double hourlyRate) {
super();
this.hourlyRate = hourlyRate;
}
@Override
double monthlyEarning() {
double montlySalary=getHourlyRate()*STAFF_MONTHLY_HOURS_WORKED;
return montlySalary;
}
@Override
public String toString() {
return "Staff[ "+super.toString() + "montly Salary: "+hourlyRate*STAFF_MONTHLY_HOURS_WORKED+"]";
}
}
//Education.java
package emp;
public class Education {
private String degree;
private String major;
private int noOfResearches;
public Education() {
super();
}
public Education(String degree, String major, int noOfResearches) {
super();
this.degree = degree;
this.major = major;
this.noOfResearches = noOfResearches;
}
public String getDegree() {
return degree;
}
public void setDegree(String degree) {
this.degree = degree;
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
public int getNoOfResearches() {
return noOfResearches;
}
public void setNoOfResearches(int noOfResearches) {
this.noOfResearches = noOfResearches;
}
}
//Faculty.java
package emp;
import java.util.Date;
public class Faculty extends Employee implements EmployeeInfo{
private enum Level { AS,AO,FU }
private Education edu;
private double salary;
public Faculty() {
super();
}
public Faculty(String lastName, String firstName, String idNumber, char sex, String birthDate) {
super(lastName, firstName, idNumber, sex, birthDate);
}
public Education getEdu() {
return edu;
}
public void setEdu(Education edu) {
this.edu = edu;
}
@Override
double monthlyEarning() {
for (Level l : Level.values())
{
if(l.equals("AS")) salary=FACULTY_MONTHLY_SALARY;
else if(l.equals("AO")) salary=FACULTY_MONTHLY_SALARY*(1.5);
else salary=FACULTY_MONTHLY_SALARY*(2.0);
}
return salary;
}
@Override
public String toString() {
return super.toString() + "monthlysalary=" + salary;
}
}
//PartTime.java
package emp;
import java.util.Date;
public class PartTime extends Staff {
private int hoursWorkedPerWeek;
public PartTime() {
super();
}
public PartTime(double hourlyRate) {
super(hourlyRate);
}
public PartTime(String lastName, String firstName, String idNumber, char sex, String birthDate) {
super(lastName, firstName, idNumber, sex, birthDate);
}
public int getHoursWorkedPerWeek() {
return hoursWorkedPerWeek;
}
public void setHoursWorkedPerWeek(int hoursWorkedPerWeek) {
this.hoursWorkedPerWeek = hoursWorkedPerWeek;
}
@Override
double monthlyEarning() {
double montlySalary=super.getHourlyRate()*hoursWorkedPerWeek*4;
return montlySalary;
}
@Override
public String toString() {
return "PartTime [hoursWorkedPerMonth=" + hoursWorkedPerWeek*4 + ", toString()=" + super.toString() + "]";
}
}
//Test.java
package emp;
import java.util.Calendar;
public class Test {
public static void main(String[] args) {
Employee[] employee={new Staff("teja","tarun","emp001",'M',"2/6/1992"),
new Faculty("teja1","ravi","emp002",'M',"22/6/1990"),
new PartTime("babu","ravi","emp003",'M',"22/6/1987")};
for(Employee e:employee){
System.out.println(e);
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.