USE FACTORY MEHTOD DESIGN USE FACTORY MEHTOD DESIGN USE FACTORY MEHTOD DESIGN US
ID: 3598035 • Letter: U
Question
USE FACTORY MEHTOD DESIGN
USE FACTORY MEHTOD DESIGN
USE FACTORY MEHTOD DESIGN
USE FACTORY MEHTOD DESIGN
USE FACTORY MEHTOD DESIGN
USE FACTORY MEHTOD DESIGN
USE FACTORY MEHTOD DESIGN
USE FACTORY MEHTOD DESIGN
USE FACTORY MEHTOD DESIGN
USE FACTORY MEHTOD DESIGN
USE FACTORY MEHTOD DESIGN
USE FACTORY MEHTOD DESIGN
USE FACTORY MEHTOD DESIGN
USE FACTORY MEHTOD DESIGN
USE FACTORY MEHTOD 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
CLASS EDUCATION
package Employee;
public class Education {
public Education() {
}
public Education(Degree degree, String major, int research) {
super();
this.degree = degree;
this.major = major;
this.research = research;
}
private Degree degree;
private String major;
private int research;
public enum Degree {
MS, PhD
}
public Degree getDegree() {
return degree;
}
public void setDegree(Degree degree) {
this.degree = degree;
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
public int getResearch() {
return research;
}
public void setResearch(int research) {
this.research = research;
}
}
CLASS EMPLOYEE
package Employee;
import java.util.Calendar;
public abstract class Employee implements Comparable<Employee> {
public Employee(String lastName, String firstName, String idNumber, Gender gender, Calendar date) {
super();
this.setLastName(lastName);
this.setFirstName(firstName);
this.setIdNumber(idNumber);
this.setGender(gender);
this.setDate(date);
}
public Employee() {
}
private String lastName;
private String firstName;
private String idNumber;
private Gender gender;
private Calendar date;
@Override
public String toString() {
return "ID Employee number : " + this.getIdNumber() + " Employee name: " + this.getFirstName() + " "
+ this.getLastName() + " Birth date: " + getDate().getTime();
}
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 Gender getGender() {
return gender;
}
public void setGender(Gender gender) {
this.gender = gender;
}
public Calendar getDate() {
return date;
}
public void setDate(Calendar date) {
this.date = date;
}
abstract float monthlyEarning();
@Override
public int compareTo(Employee o) {
return Integer.parseInt(this.idNumber) > Integer.parseInt(o.idNumber) ? -1 : 1;
}
}
CLASS EMPLOYEEINFO
package Employee;
public interface EmployeeInfo {
final float FACULTY_MONTHLY_SALARY = (float) 6000.00;
final int STAFF_MONTHLY_HOURS_WORKED = 160;
}
CLASS FACULTY
package Employee;
import java.util.Calendar;
public class Faculty extends Employee {
public Faculty(String lastName, String firstName, String idNumber, Gender gender, Calendar date, Level level,
Education education) {
super(lastName, firstName, idNumber, gender, date);
this.level = level;
this.education = education;
}
public Faculty() {
}
private Level level;
private Education education;
@Override
float monthlyEarning() {
// TODO Auto-generated method stub
switch (level) {
case AS:
return EmployeeInfo.FACULTY_MONTHLY_SALARY;
case AO:
return EmployeeInfo.FACULTY_MONTHLY_SALARY * (float) 1.5;
case FU:
return EmployeeInfo.FACULTY_MONTHLY_SALARY * 2;
default:
return EmployeeInfo.FACULTY_MONTHLY_SALARY;
}
}
public Education getEducation() {
return education;
}
public void setEducation(Education education) {
this.education = education;
}
public Level getLevel() {
return level;
}
public void setLevel(Level level) {
this.level = level;
}
public enum Level {
/*
* "AS": assistant professor "AO": associate professor "FU": professor
*/
AS, AO, FU;
}
@Override
public String toString() {
String prof;
switch (level) {
case AS:
prof = "Assiatant Professor";
break;
case AO:
prof = "Associate Professor";
break;
case FU:
prof = "Full Professor";
break;
default:
prof = "Assiatant Professor";
break;
}
return "ID Employee number : " + this.getIdNumber() + " Employee name: " + this.getFirstName() + " "
+ this.getLastName() + " Birth date: " + getDate().getTime() + " " + prof + " "
+ "Monthly salary : " + monthlyEarning();
}
}
ENUM GENDER
package Employee;
public enum Gender {
M,F;
}
CLASS PARTIME
package Employee;
import java.util.Calendar;
public class Partime extends Staff {
private float hoursWorkedPerWeek;
public Partime() {
super();
}
public Partime(float horlyRate) {
super(horlyRate);
}
public Partime(String lastName, String firstName, String idNumber, Gender gender, Calendar date, float hourlyRate) {
super(lastName, firstName, idNumber, gender, date, hourlyRate);
}
public float getHoursWorkedPerWeek() {
return hoursWorkedPerWeek;
}
public void setHoursWorkedPerWeek(float hoursWorkedPerWeek) {
this.hoursWorkedPerWeek = hoursWorkedPerWeek;
}
@Override
public float monthlyEarning() {
return hoursWorkedPerWeek * 4 * getHourlyRate();
}
@Override
public String toString() {
return "ID Employee number : " + this.getIdNumber() + " Employee name: " + this.getFirstName() + " "
+ this.getLastName() + " Birth date: " + getDate().getTime() + " Hours works per month : "
+ getHoursWorkedPerWeek() * 4 + " " + "Monthly salary : " + monthlyEarning();
}
}
CLASS STAFF
package Employee;
import java.util.Calendar;
public class Staff extends Employee {
public Staff(String lastName, String firstName, String idNumber, Gender gender, Calendar date, float hourlyRate) {
super(lastName, firstName, idNumber, gender, date);
this.hourlyRate = hourlyRate;
}
public Staff(float horlyRate) {
this.hourlyRate = hourlyRate;
}
public Staff() {
}
private float hourlyRate;
@Override
public float monthlyEarning() {
return hourlyRate * 160;
}
public float getHourlyRate() {
return hourlyRate;
}
public void setHourlyRate(float hourlyRate) {
this.hourlyRate = hourlyRate;
}
@Override
public String toString() {
return "ID Employee number : " + this.getIdNumber() + " Employee name: " + this.getFirstName() + " "
+ this.getLastName() + " Birth date: " + getDate().getTime() + " FULL TIME " + "Monthly salary : "
+ monthlyEarning();
}
}
CLASS TESTDRIVER
package Employee;
import java.util.Arrays;
import java.util.Calendar;
import Employee.Education.Degree;
import Employee.Faculty.Level;
public class TestDriver {
static Employee[] employee = new Employee[9];
/**
* @param args
*/
public static void main(String args[]) {
/*
* Last name: Allen First name: Paita ID: 123 Sex: M Birth date: 2/23/59 Hourly
* rate: $50.00
*/
Staff staff1 = new Staff();
staff1.setFirstName("Paita");
staff1.setLastName("Allen");
staff1.setIdNumber("123");
staff1.setGender(Gender.M);
Calendar calendar = Calendar.getInstance();
calendar.set(1959, 2, 23);
staff1.setDate(calendar);
staff1.setHourlyRate(50);
employee[0] = staff1;
/*
* Last name: Zapata First Name: Steven ID: 456 Sex: F Birth date: 7/12/64
* Hourly rate: $35.00
*/
Staff staff2 = new Staff();
staff2.setFirstName("Steven");
staff2.setLastName("Zapata");
staff2.setIdNumber("456");
staff2.setGender(Gender.F);
calendar = Calendar.getInstance();
calendar.set(1964, 7, 12);
staff2.setDate(calendar);
staff2.setHourlyRate(35);
employee[1] = staff2;
/*
* Last name:Rios First name:Enrique ID: 789 Sex: M Birth date: 6/2/70 Hourly
* rate: $40.00
*/
Staff staff3 = new Staff();
staff3.setFirstName("Enrique");
staff3.setLastName("Rios");
staff3.setIdNumber("789");
staff3.setGender(Gender.M);
calendar = Calendar.getInstance();
calendar.set(1970, 6, 2);
staff3.setDate(calendar);
staff3.setHourlyRate(40);
employee[2] = staff3;
/*
* Last name: Johnson First name: Anne ID: 243 Sex: F Birth date: 4/27/62 Level:
* Full Degree: Ph.D Major: Engineering Reseach: 3
*/
Faculty faculty1 = new Faculty();
faculty1.setFirstName("Anne");
faculty1.setLastName("Johnson");
faculty1.setIdNumber("243");
faculty1.setGender(Gender.F);
calendar = Calendar.getInstance();
calendar.set(1962, 4, 27);
faculty1.setDate(calendar);
faculty1.setLevel(Level.FU);
Education education = new Education();
education.setDegree(Degree.PhD);
education.setMajor("Engineering");
education.setResearch(3);
faculty1.setEducation(education);
employee[3] = faculty1;
/*
* Last name: Bouris First name: William ID: 791 Sex: F Birth date: 3/14/75
* Level: Associate Degree: Ph.D Major: English Reseach: 1
*
*/
Faculty faculty2 = new Faculty();
faculty2.setFirstName("William");
faculty2.setLastName("Bouris");
faculty2.setIdNumber("791");
faculty2.setGender(Gender.F);
calendar = Calendar.getInstance();
calendar.set(1975, 3, 14);
faculty2.setDate(calendar);
faculty2.setLevel(Level.AO);
Education education2 = new Education();
education2.setDegree(Degree.PhD);
education2.setMajor("English");
education2.setResearch(1);
faculty2.setEducation(education2);
employee[4] = faculty2;
/*
* Last name: Andrade First name: Christopher ID: 623 Sex: F Birth date: 5/22/80
* Level: Assistant Degree: MS Major: Physical Education Research: 0
*
*/
Faculty faculty3 = new Faculty();
faculty3.setFirstName("Christopher");
faculty3.setLastName("Andrade");
faculty3.setIdNumber("623");
faculty3.setGender(Gender.F);
calendar = Calendar.getInstance();
calendar.set(1980, 5, 22);
faculty3.setDate(calendar);
faculty3.setLevel(Level.AS);
Education education3 = new Education();
education3.setDegree(Degree.MS);
education3.setMajor("Physical Education");
education3.setResearch(0);
faculty3.setEducation(education3);
employee[5] = faculty3;
/*
* Last name: Guzman First name: Augusto ID: 455 Sex: F Birth date: 8/10/77
* Hourly rate: $35.00 Hours worked per week: 30
*/
Partime partime1 = new Partime();
partime1.setFirstName("Augusto");
partime1.setLastName("Guzman");
partime1.setIdNumber("455");
partime1.setGender(Gender.F);
calendar = Calendar.getInstance();
calendar.set(1977, 8, 10);
partime1.setDate(calendar);
partime1.setHourlyRate(35);
partime1.setHoursWorkedPerWeek(30);
employee[6] = partime1;
/*
* Last name: Depirro First name: Martin ID: 678 Sex: F Birth date: 9/15/87
* Hourly rate: $30.00 Hours worked per week:15
*
*/
Partime partime2 = new Partime();
partime2.setFirstName("Martin");
partime2.setLastName("Depirro");
partime2.setIdNumber("678");
partime2.setGender(Gender.F);
calendar = Calendar.getInstance();
calendar.set(1987, 9, 15);
partime2.setDate(calendar);
partime2.setHourlyRate(30);
partime2.setHoursWorkedPerWeek(15);
employee[7] = partime2;
/*
* Last name: Aldaco First name: Marque ID: 945 Sex: M Birth date: 11/24/88
* Hourly rate: $20.00 Hours worked per week: 35
*
*/
Partime partime3 = new Partime();
partime3.setFirstName("Marque");
partime3.setLastName("Aldaco");
partime3.setIdNumber("945");
partime3.setGender(Gender.M);
calendar = Calendar.getInstance();
calendar.set(1988, 11, 24);
partime3.setDate(calendar);
partime3.setHourlyRate(20);
partime3.setHoursWorkedPerWeek(35);
employee[8] = partime3;
diplayAllEmployeeData();
displayTotalSalaryForPartTime();
}
private static void displayTotalSalaryForPartTime() {
System.out.println(" ******* Total Salary For PartTime ******* ");
float totalIncomeOfPartimeEmploees = 0;
float totalIncomeOfAllEmploees = 0;
for (Employee employee : TestDriver.employee) {
totalIncomeOfAllEmploees = totalIncomeOfAllEmploees + employee.monthlyEarning();
if (employee instanceof Partime) {
System.out.println(employee.toString());
totalIncomeOfPartimeEmploees = totalIncomeOfPartimeEmploees + employee.monthlyEarning();
}
}
System.out.println(" ******* Total Income Data******* ");
System.out.println("Total income under partime category is " + totalIncomeOfPartimeEmploees);
System.out.println("Total income under all employee category is " + totalIncomeOfAllEmploees);
Arrays.sort(employee);
System.out.println(" ******* All Data Sorted on Id number******* ");
for (Employee employee : TestDriver.employee) {
System.out.println(employee.toString());
}
}
private static void diplayAllEmployeeData() {
System.out.println(" ******* All Data ******* ");
for (Employee employee : TestDriver.employee) {
System.out.println(employee.toString());
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.