0.Use Factory Design Method
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
In the answer, I have created everything in the requirements. Implemented an interface EmployeeInfo with FACULTY_MONTHLY_SALARY and STAFF_MONTHLY_HOURS_WORKED constants. Implemented abstract Employee class with all the required attributes. For, date of birth, a Date object is defined and used a SimpleDateFormat object to parse and format date. Defined toString() method; and declared an abstract method monthlyEarning(). Extended a class Staff from Employee ; implemented all the attributes and the overridden function monthlyEarning(). Created Education class with required attributes. Implemented a Faculty class extending from Employee. Created a class Partime extending from Staff. All the required Constructors, getters and setters defined for all classes. Created a TestDriver class which contains the main function. In the main function , a SimpleDateFormat object is defined to parse a Date from String; which is really helpful. Then an array of Employee class is defined. Created several objects – Staff, Faculty & Partime using Polymorphism. Then displayed all the details of Staff , Faculties, and Partime employees. Total salary of all employees are calculated and displayed; total salary of Partime employees also displayed. Employees are then sorted on the basis of their ID in descending order using Comparator and displayed. Employees are then sorted in the ascending order of their lastname and displayed. Then a Cloning demonstration is displayed. Remember that, I’ve selected an object from the Employee array which is supposed to be of Faculty type. If you try cloning, make sure you try the same type objects, or else it’ll return unexpected values or null. I didn’t get time to make it completely bullet proof. And go through all the javadoc comments included. Thanks.
//EmployeeInfo.java file
public interface EmployeeInfo {
final float FACULTY_MONTHLY_SALARY=6000.00f; /*constant variables*/
final int STAFF_MONTHLY_HOURS_WORKED =160;
}
//Employee.java file
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public abstract class Employee implements Cloneable {
String firstname, lastname, id;
char sex;
Date dob;
Employee() {
/* default constructor */
}
Employee(String firstname, String lastname, String id, char sex, Date dob) {
/**
* parameterized constructor
*/
this.firstname = firstname;
this.lastname = lastname;
this.id = id;
this.sex = sex;
this.dob = dob;
}
public String toString() {
/**
* method to return a string containing all details
*/
SimpleDateFormat dateformat = new SimpleDateFormat("mm/dd/yy");
/**
* an object to parse date from string and to display a date in required
* format
*/
String str = "ID Employee number: " + id + "\nEmployee Last name: "
+ lastname + ", Firstname: " + firstname + "\nBirth Date: "
+ dateformat.format(dob);
return str;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public char getSex() {
return sex;
}
public void setSex(char sex) {
this.sex = sex;
}
public Date getDob() {
return dob;
}
public void setDob(Date dob) {
this.dob = dob;
}
/**
* abstract method to return monthly earning
*
* @return monthly earning in double format
*/
public abstract double monthlyEarning();
@Override
protected Object clone() throws CloneNotSupportedException {
/**
* will throw an Exception if Object cloning is not supported
*/
return super.clone();
}
}
//Education.java file
public class Education {
String degree,major;
int researches;
public Education(String degree,String major,int researches) {
/**
* parameterized constructor
*/
this.degree=degree;
this.major=major;
this.researches=researches;
}
public Education() {
/*Default constructor*/
}
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 getResearches() {
return researches;
}
public void setResearches(int researches) {
this.researches = researches;
}
}
//Faculty.java file
import java.util.Date;
public class Faculty extends Employee implements Cloneable{
Level level;
Education education;
public Faculty(String firstname,String lastname,String id,char sex,Date dob,Level level,Education education) {
/**
* parameterized constructor
*/
super(firstname,lastname,id, sex,dob); /*passing values to superclass constructor*/
this.level=level;
this.education=education;
}
public Faculty() {
/*default constructor*/
}
@Override
public double monthlyEarning() {
if(level==Level.AS){
return EmployeeInfo.FACULTY_MONTHLY_SALARY;/**return the salary of Assistant proff*/
}else if(level==Level.AO){
return (1.5*EmployeeInfo.FACULTY_MONTHLY_SALARY); /**return the salary of Assoc proff*/
}else if(level==Level.FU){
return (2*EmployeeInfo.FACULTY_MONTHLY_SALARY);/**return the salary of full time proff*/
}
return 0;
}
enum Level{
/**
* an enumeration variable to store the level of
* professor. AS- Assistant,AO- Associate and
* FU for Full time.
*/
AS,
AO,
FU
}
public Level getLevel() {
return level;
}
public void setLevel(Level level) {
this.level = level;
}
public Education getEducation() {
return education;
}
public void setEducation(Education education) {
this.education = education;
}
public String toString() {
String role="";
if(level==Level.AS){
role="Assistant Professor";
}else if(level==Level.AO){
role="Associate Professor";
}else if(level==Level.FU){
role="Full Professor";
}
String str=super.toString()+"\n"+role+"\nMonthly Salary: "+monthlyEarning();
return str;
}
@Override
protected Object clone() throws CloneNotSupportedException {
return this;
}
}
//Partime.java file
import java.util.Date;
public class Partime extends Staff {
int hours_worked_per_week;
//float hourly_rate;
public Partime(String firstname,String lastname,String id,char sex,Date dob,double hourly_rate,int hours_worked_per_week) {
super(firstname,lastname,id, sex,dob,hourly_rate);
this.hours_worked_per_week=hours_worked_per_week;
//this.hourly_rate=hourly_rate;
}
public Partime() {
/*default constructor*/
}
@Override
public double monthlyEarning() {
return hourly_rate*hours_worked_per_week*4;
}
public int getHours_worked_per_week() {
return hours_worked_per_week;
}
public void setHours_worked_per_week(int hours_worked_per_week) {
this.hours_worked_per_week = hours_worked_per_week;
}
public String toString(){
return super.toString()+"\nHours worked per month: "+(hours_worked_per_week*4);
}
}
//Staff.java file
import java.util.Date;
public class Staff extends Employee {
double hourly_rate;
public Staff() {
/*default constructor*/
}
public Staff(String firstname,String lastname,String id,char sex,Date dob,double hourly_rate){
super(firstname,lastname,id, sex,dob); /*passing values to superclass constructor*/
this.hourly_rate=hourly_rate;
}
@Override
public double monthlyEarning() {
return hourly_rate*160;
}
public double getHourly_rate() {
return hourly_rate;
}
public void setHourly_rate(float hourly_rate) {
this.hourly_rate = hourly_rate;
}
public String toString(){
String str=super.toString()+"\nMonthly Salary: "+monthlyEarning();
return str;
}
}
//TestDriver.java file
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import employee.Faculty.Level;
public class TestDriver {
public static void main(String[] args) {
SimpleDateFormat sdf=new SimpleDateFormat("mm/dd/yy"); /*this is used to parse a Date from String text*/
Employee[] employee=new Employee[9];/*an array of Employees (Staff,Faculty,Partime)*/
try {
employee[0]=new Staff("Paita", "Allen", "123", 'M', sdf.parse("2/23/59"), 50.00); /*creating a new Staff object*/
employee[1]=new Staff("Steven", "Zapata", "456", 'F', sdf.parse("7/12/64"), 35.00);
employee[2]=new Staff("Enrique", "Rios", "789", 'M', sdf.parse("6/2/70"), 40.00);
employee[3]=new Faculty("Anne", "Johnson", "243", 'F', sdf.parse("4/27/62"), Level.FU, new Education("Ph.D", "Engineering", 3));/*creating a new Faculty object; and an Edcuation object is passed as one of the arguments*/
employee[4]=new Faculty("William", "Bouris", "791", 'F', sdf.parse("3/14/75"), Level.AO, new Education("Ph.D", "English", 1));
employee[5]=new Faculty("Christopher", "Andrade", "623", 'F', sdf.parse("5/22/80"), Level.AS, new Education("MS", "Physical Education", 0));
employee[6]=new Partime("Augusto", "Guzman", "455", 'F', sdf.parse("8/10/77"), 35.00, 30);
employee[7]=new Partime("Martin", "Depirro", "678", 'F', sdf.parse("9/15/87"), 30.00, 15);
employee[8]=new Partime("Marque", "Aldaco", "945", 'M', sdf.parse("11/24/88"), 20.00, 35);
System.out.println("details of all STAFF employees");
for (Employee emp : employee) {
if(emp.getClass()==Staff.class){ /*checking if its a Staff object*/
System.out.println(emp.toString());
System.out.println("---");
}
}
System.out.println();
System.out.println("details of all FACULTY employees");
for (Employee emp : employee) {
if(emp.getClass()==Faculty.class){ /*checking if its a Faculty object*/
System.out.println(emp.toString());
System.out.println("---");
}
}
System.out.println();
System.out.println("details of all PART TIME employees");
for (Employee emp : employee) {
if(emp.getClass()==Partime.class){ /*checking if its a Partime object*/
System.out.println(emp.toString());
System.out.println("---");
}
}
float total_salary_all_employees=0;
float total_salary_partime_employees=0;
for (Employee emp : employee) {
if(emp.getClass()==Partime.class){ /*checking if its a Partime object*/
total_salary_partime_employees+=emp.monthlyEarning();
}
total_salary_all_employees+=emp.monthlyEarning();
}
System.out.println("Total salary of all part time employees: "+total_salary_partime_employees);
System.out.println("Total salary of all employees: "+total_salary_all_employees);
System.out.println("Employee Info in descending order of employee id\n");
Collections.sort(Arrays.asList(employee),new Comparator<Employee>() {
/**
* Sorting array using Comparator on the basis of descending order
* of Employee ID
*/
public int compare(Employee o1, Employee o2) {
return o2.getId().compareToIgnoreCase(o1.getId());
}
});
for (Employee emp : employee) {
System.out.println(emp.toString());
System.out.println("\n");
}
System.out.println("Employee Info in ascending order of lastname \n");
Collections.sort(Arrays.asList(employee),new Comparator<Employee>() {
/**
* Sorting array using Comparator on the basis of ascending order
* of lastname
*/
public int compare(Employee o1, Employee o2) {
return o1.getLastname().compareToIgnoreCase(o2.getLastname());
}
});
for (Employee emp : employee) {
System.out.println(emp.toString());
System.out.println("\n");
}
try {
System.out.println("Cloning demonstration");
Faculty clonedObject = (Faculty) employee[3].clone();
/**
* Remember!
* we're doing this because employee[3] is supposed to be a
* Faculty object,if not,it wont return expected values.
*/
System.out.println("original object:");
System.out.println(employee[3].toString()); /*original object*/
System.out.println("Cloned Object: ");
System.out.println(clonedObject.toString()); /*cloned object*/
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
} catch (ParseException e) {
e.printStackTrace();
}
}
}
details of all STAFF employees
ID Employee number: 123
Employee Last name: Allen, Firstname: Paita
Birth Date: 02/23/59
Monthly Salary: 8000.0
---
ID Employee number: 456
Employee Last name: Zapata, Firstname: Steven
Birth Date: 07/12/64
Monthly Salary: 5600.0
---
ID Employee number: 789
Employee Last name: Rios, Firstname: Enrique
Birth Date: 06/02/70
Monthly Salary: 6400.0
---
0.Use Factory Design Method 1. Implement an interface called EmployeeInfo with the following constant variables: FACULTY_MONTHLY_SALARY...
Rewrite following code down below using Factory Pattern. -------------------------Staff.java--------------------------- import java.util.*; public class Staff extends Employee { private int HourlyRate; /**Constructor Staff which initiates the values*/ public Staff() { super(); HourlyRate=0; } /**Overloaded constructor method * @param ln last name * @param fn first name * @param ID Employee ID * @param sex Sex * @param hireDate Hired Date * @param hourlyRate Hourly rate for the work...
IN JAVADesign a Payroll class with the following fields:• name: a String containing the employee's name• idNumber: an int representing the employee's ID number• rate: a double containing the employee's hourly pay rate• hours: an int representing the number of hours this employee has workedThe class should also have the following methods:• Constructor: takes the employee's name and ID number as arguments• Accessors: allow access to all of the fields of the Payroll class• Mutators: let the user assign values...
Create an abstract class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create an abstract method called earnings. Create another class HourlyEmployee that inherits from the abstract Employee class. HourEmployee must use the inherited parent class variables and add in attributes HourlyRate and HoursWorked. Your HourEmployee class should...
Create an abstract class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create an abstract method called earnings. Create another class HourlyEmployee that inherits from the abstract Employee class. HourEmployee must use the inherited parent class variables and add in attributes HourlyRate and HoursWorked. Your HourEmployee class should...
Design and implement a C++ class called Date that has the following private member variables month (int) day (nt) . year (int Add the following public member functions to the class. Default Constructor with all default parameters: The constructors should use the values of the month, day, and year arguments passed by the client program to set the month, day, and year member variables. The constructor should check if the values of the parameters are valid (that is day is...
Java program. Code the following interfaces, implement them, and use the interface as a parameter, respectively: a. An interface called Printable with a void print() method. b. An interface called EmployeeType with FACULTY and CLASSIFIED integer data. The value of FACULTY is 1 and CLASSIFIED is 2. a. A class called Employee to implement the two interfaces. Its constructor will initialize three instance data as name, employeeType, and salary. Implementation of method print() will display name, employeeType, and salary; salary...
In the processLineOfData method, write the code to handle case "H" of the switch statement such that: • An HourlyEmployee object is created using the firstName, lastName, rate, and hours local variables. Notice that rate and hours need to be converted from String to double. You may use parseDouble method of the Double class as follows: Double.parseDouble(rate) Call the parsePaychecks method in this class passing the Hourly Employee object created in the previous step and the checks variable. Call the...
Use C++ to create a class called Student, which represents the students of a university. A student is defined with the following attributes: id number (int), first name (string), last name (string), date of birth (string), address (string). and telephone (area code (int) and 7-digit telephone number(string). The member functions of the class Student must perform the following operations: Return the id numb Return the first name of the student Modify the first name of the student. . Return the...
Please provide the code for the last part(client side program). yes i have all the class implementations. ``` person.h #ifndef PERSON_H #define PERSON_H #include <string> using namespace std; class person { public: person(); string getname() const; string getadd() const; string getemail() const; string getphno() const; string toString() const; private: string name; string add; string email; string phno; }; ```person.cpp #include "person.h" person::person() { name = "XYZ"; add="IIT "; email="%%%%"; phno="!!!!!"; } string person::getname() const { return name; } string person::getadd()...
C++ implement and use the methods for a class called Seller that represents information about a salesperson. The Seller class Use the following class definition: class Seller { public: Seller(); Seller( const char [], const char[], const char [], double ); void print(); void setFirstName( const char [] ); void setLastName( const char [] ); void setID( const char [] ); void setSalesTotal( double ); double getSalesTotal(); private: char firstName[20]; char lastName[30]; char ID[7]; double salesTotal; }; Data Members The...