Java Programing Employee and ProductionWorker Classes, ShiftSupervisor Class, an
ID: 3683604 • Letter: J
Question
Java Programing
Employee and ProductionWorker Classes, ShiftSupervisor Class, and TeamLeader Class: Design a class named Employee. The class should keep the following information in fields: Employee name, Employee number in the format xxx-L, where each x is a digit within the range 0-9 and the L is a letter within the range A-M., and Hire date Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named ProductionWorker that inherits from the Employee class. The ProductionWorker class should have fields to hold the following information: Shift (an integer), and Hourly pay rate (a double) The workday is divided into two shifts: day and night. The shift field will be an integer value representing the shift that the employee works. The day shift is shift 1 and the night shift is shift 2. Write one or more constructors and the appropriate accessor and mutator methods for the class. ShiftSupervisor Class: In a particular factory a shift supervisor is a salaried employee who supervises a shift. In addition to a salary, the shift supervisor earns a yearly bonus when his or her shift meets production goals. Design a ShiftSupervisor class that inherits from the Employee class. The ShiftSupervisor class should have a field that holds the annual salary and a field that holds the annual production bonus that a shift supervisor has earned. Write one or more constructors and the appropriate accessor and mutator methods for the class. TeamLeader Class: In a particular factory, a team leader is an hourly paid production worker that leads a small team. In addition to hourly pay, team leaders earn a fixed monthly bonus. Team leaders are required to attend a minimum number of hours of training per year. Design a TeamLeader class that inherits from the ProductionWorker class. The TeamLeader class should have fields for the monthly bonus amount, the required number of training hours, and the number of training hours that the team leader has attended. Write one or more constructors and the appropriate accessor and mutator methods for the class Demonstrate the class by writing a program that uses a TeamLeader object. Demonstrate these classes by writing a driver class (main()) which should test all the classes.
Explanation / Answer
EmployeeDemo.java
public class EmployeeDemo {
public static void main(String[] args) {
// create a new basic employee object
Employee ee = new Employee("Dominic Giglio", "123-A", "11/25/2011");
// print out the basic employee object
System.out.println(" This is a basic employee object: ");
System.out.println(ee);
// create a Production Worker object
ProductionWorker pw1 = new ProductionWorker("Michael Giglio", "456-B", "11/24/2011", 2, 30.00);
// create a copy of the first Production Worker object
ProductionWorker pw2 = new ProductionWorker(pw1);
// print out the first Production Worker object
System.out.println(" This is the first Production Worker object: ");
System.out.println(pw1);
// print out the second Production Worker object
System.out.println(" This is the second Production Worker object: ");
System.out.println(pw2);
// create a Shift Supervisor object
ShiftSupervisor ss1 = new ShiftSupervisor("John Proodian", "789-C", "11/20/2011", 12000, 3000);
// create a copy of the first Shift Supervisor object
ShiftSupervisor ss2 = new ShiftSupervisor(ss1);
// print out the first Shift Supervisor object
System.out.println(" This is the first Shift Supervisor object: ");
System.out.println(ss1);
// print out the second Shift Supervisor object
System.out.println(" This is the second Shift Supervisor object: ");
System.out.println(ss2);
// create a Team Leader object
TeamLeader tl1 = new TeamLeader("Katie Proodian", "987-D", "11/10/2011", 1, 15.00, 1500, 100, 50);
// create a copy of the first Team Leader object
TeamLeader tl2 = new TeamLeader(tl1);
// print out the first Team Leader object
System.out.println(" This is the first Team Leader object: ");
System.out.println(tl1);
// print out the second Team Leader object
System.out.println(" This is the second Team Leader object: ");
System.out.println(tl2);
} // end main() method
} // end EmployeeDemo class
Employee.java
public class Employee {
// private fields
private String name;
private String number; // format: XXX-L where X is a number 0-9 and L is a letter from A-M
private String hireDate;
// public methods
/**
* Default constructor.
* This constructor sets the name, number and hire date for an employee
* @param name The employee's name
* @param number The employee's number
* @param hireDate The date the employee was hired
*/
public Employee(String name, String number, String hireDate) {
this.name = new String(name);
this.number = new String(number);
this.hireDate = new String(hireDate);
}
/**
* Name accessor (getter)
* @return the value of the name field
*/
public String getName() {
return name;
}
/**
* Name mutator (setter)
* @param name new value for the name field
*/
public void setName(String name) {
this.name = name;
}
/**
* Number accessor (getter)
* @return the value of the number field
*/
public String getNumber() {
return number;
}
/**
* Number mutator (setter)
* @param number new value for the number field
*/
public void setNumber(String number) {
this.number = number;
}
/**
* Hire Date accessor (getter)
* @return the value of the hireDate field
*/
public String getHireDate() {
return hireDate;
}
/**
* Hire Date mutator (setter)
* @param hireDate new value for the hireDate field
*/
public void setHireDate(String hireDate) {
this.hireDate = hireDate;
}
/**
* To String Method.
* This method will print a nicely formatted string representation of the
* class' fields
*/
public String toString() {
String str = "Employee Name: " + name +
" Employee Number: " + number +
" Employee Hire Date: " + hireDate;
return str;
}
}
ProductionWorker.java
public class ProductionWorker extends Employee {
// private fields
private int shift;
private double hourlyPayRate;
// public methods
/**
* Default constructor.
* This constructor sets the name, number and hire date for an Employee.
* Then it sets up the specific fields for a ProductionWorker.
* @param name The employee's name
* @param number The employee's number
* @param hireDate The date the employee was hired
* @param shift The shift the employee works
* @param payRate How much the employee is paid per hour
*/
public ProductionWorker(String name, String number, String hireDate, int shift, double payRate) {
super(name, number, hireDate);
this.shift = shift;
this.hourlyPayRate = payRate;
}
/**
* Copy constructor.
* This constructor will create a new ProductionWorker by copying another.
* @param pw An existing ProductionWorker object
*/
public ProductionWorker(ProductionWorker pw) {
super(pw.getName(), pw.getNumber(), pw.getHireDate());
this.shift = pw.getShift();
this.hourlyPayRate = pw.getPayRate();
}
/**
* Shift accessor (getter)
* @return the value of the shift field
*/
public int getShift() {
return shift;
}
/**
* Shift mutator (setter)
* @param newShift new value for the shift field
*/
public void setShift(int newShift) {
this.shift = newShift;
}
/**
* Hourly Pay Rate accessor (getter)
* @return the value of the hourlyPayRate field
*/
public double getPayRate() {
return hourlyPayRate;
}
/**
* Hourly Pay Rate mutator (setter)
* @param newPayRate new value for the hourlyPayRate field
*/
public void setPayRate(double newPayRate) {
this.hourlyPayRate = newPayRate;
}
/**
* To String Method.
* This method will print a nicely formatted string representation of the
* class' fields
*/
public String toString() {
String str = super.toString();
str += " Employee Shift: " + shift +
" Employee Hourly Pay Rate: " + hourlyPayRate;
return str;
}
}
ShiftSupervisor.java
public class ShiftSupervisor extends Employee {
// private fields
private double annualSalary;
private double annualBonus;
// public methods
/**
* Default constructor.
* This constructor sets the name, number and hire date for an Employee.
* Then it sets up the specific fields for a ShiftSupervisor.
* @param name The employee's name
* @param number The employee's number
* @param hireDate The date the employee was hired
* @param annualSalary The employee's annual salary
* @param annualBonus The employee's annual bonus
*/
public ShiftSupervisor(String name, String number, String hireDate, double salary, double bonus) {
super(name, number, hireDate);
this.annualSalary = salary;
this.annualBonus = bonus;
}
/**
* Copy constructor.
* This constructor will create a new ShiftSupervisor by copying another.
* @param ss An existing ShiftSupervisor object
*/
public ShiftSupervisor(ShiftSupervisor ss) {
super(ss.getName(), ss.getNumber(), ss.getHireDate());
this.annualSalary = ss.getAnnualSalary();
this.annualBonus = ss.getAnnualBonus();
}
/**
* Annual Salary accessor (getter)
* @return the value of the annualSalary field
*/
public double getAnnualSalary() {
return annualSalary;
}
/**
* Annual Salary mutator (setter)
* @param newSalary new value for the annualSalary field
*/
public void setAnnualSalary(double newSalary) {
this.annualSalary = newSalary;
}
/**
* Annual Bonus accessor (getter)
* @return the value of the annualBonus field
*/
public double getAnnualBonus() {
return annualBonus;
}
/**
* Annual Bonus mutator (setter)
* @param newBonus new value for the annualBonus field
*/
public void setAnnualBonus(double newBonus) {
this.annualBonus = newBonus;
}
/**
* To String Method.
* This method will print a nicely formatted string representation of the
* class' fields
*/
public String toString() {
String str = super.toString();
str += " Employee Annual Salary: " + annualSalary +
" Employee Annual Bonus: " + annualBonus;
return str;
}
}
TeamLeader.java
public class TeamLeader extends ProductionWorker {
// private fields
private double monthlyBonus;
private double requiredTrainingHours;
private double completedTrainingHours;
// public methods
/**
* Default constructor.
* This constructor sets the name, number and hire date for an Employee.
* It also sets the shift and hourly pay rate for a Production Worker.
* And finally sets it's own bonus and training hours fields.
* @param name The employee's name
* @param number The employee's number
* @param hireDate The date the employee was hired
* @param shift The shift the employee works
* @param payRate How much the employee is paid per hour
* @param monthlyBonus The employee's monthly bonus
* @param rth The employee's required training hours
* @param cth The employee's completed training hours
*/
public TeamLeader(String name, String number, String hireDate, int shift, double payRate, double monthlyBonus, double rth, double cth) {
super(name, number, hireDate, shift, payRate);
this.monthlyBonus = monthlyBonus;
this.requiredTrainingHours = rth;
this.completedTrainingHours = cth;
}
/**
* Copy constructor.
* This constructor will create a new TeamLeader by copying another.
* @param tl An existing TeamLeader object
*/
public TeamLeader(TeamLeader tl) {
super(tl.getName(), tl.getNumber(), tl.getHireDate(), tl.getShift(), tl.getPayRate());
this.monthlyBonus = tl.getMonthlyBonus();
this.requiredTrainingHours = tl.getRequiredTrainingHours();
this.completedTrainingHours = tl.getCompletedTrainingHours();
}
/**
* Monthly Bonus accessor (getter)
* @return the value of the monthlyBonus field
*/
public double getMonthlyBonus() {
return monthlyBonus;
}
/**
* Monthly Bonus mutator (setter)
* @param newBonus new value for the monthlyBonus field
*/
public void setMonthlyBonus(double bonus) {
this.monthlyBonus = bonus;
}
/**
* Required Training Hours accessor (getter)
* @return the value of the requiredTrainingHours field
*/
public double getRequiredTrainingHours() {
return requiredTrainingHours;
}
/**
* Required Training Hours mutator (setter)
* @param hours new value for the requiredTrainingHours field
*/
public void setRequiredTrainingHours(double hours) {
this.requiredTrainingHours = hours;
}
/**
* Completed Training Hours accessor (getter)
* @return the value of the completedTrainingHours field
*/
public double getCompletedTrainingHours() {
return completedTrainingHours;
}
/**
* Completed Training Hours mutator (setter)
* @param hours new value for the completedTrainingHours field
*/
public void setCompletedTrainingHours(double hours) {
this.completedTrainingHours = hours;
}
/**
* To String Method.
* This method will print a nicely formatted string representation of the
* class' fields
*/
public String toString() {
String str = super.toString();
str += " Employee Monthly Bonus: " + monthlyBonus +
" Employee Required Training Hours: " + requiredTrainingHours +
" Employee Completed Training Hours: " + completedTrainingHours;
return str;
}
}
sample output
This is a basic employee object:
Employee Name: Dominic Giglio
Employee Number: 123-A
Employee Hire Date: 11/25/2011
This is the first Production Worker object:
Employee Name: Michael Giglio
Employee Number: 456-B
Employee Hire Date: 11/24/2011
Employee Shift: 2
Employee Hourly Pay Rate: 30.0
This is the second Production Worker object:
Employee Name: Michael Giglio
Employee Number: 456-B
Employee Number: 789-C
Employee Hire Date: 11/20/2011
Employee Annual Salary: 12000.0
Employee Annual Bonus: 3000.0
This is the second Shift Supervisor object:
Employee Name: John Proodian
Employee Number: 789-C
Employee Hire Date: 11/20/2011
Employee Annual Salary: 12000.0
Employee Annual Bonus: 3000.0
This is the first Team Leader object:
Employee Name: Katie Proodian
Employee Number: 987-D
Employee Hire Date: 11/10/2011
Employee Shift: 1
Employee Hourly Pay Rate: 15.0
Employee Monthly Bonus: 1500.0
Employee Required Training Hours: 100.0
Employee Completed Training Hours: 50.0
This is the second Team Leader object:
Employee Name: Katie Proodian
Employee Number: 987-D
Employee Hire Date: 11/10/2011
Employee Shift: 1
Employee Hourly Pay Rate: 15.0
Employee Monthly Bonus: 1500.0
Employee Required Training Hours: 100.0
Employee Completed Training Hours: 50.0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.