Answer to Question #300801 in Java | JSP | JSF for terry

Question #300801

In a particular factory, the 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 extends the Production Worker Class. The LeamLeader 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. Demo the class by using a program that uses the TeamLeader object. 


1
Expert's answer
2022-02-22T06:45:54-0500


class Employee {


	private String name;
	private String number;
	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 + "\nEmployee Number: " + number + "\nEmployee Hire Date: " + hireDate;
		return str;
	}
}


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 productionWorker An existing ProductionWorker object
	 */
	public ProductionWorker(ProductionWorker productionWorker) {
		super(productionWorker.getName(), productionWorker.getNumber(), productionWorker.getHireDate());
		this.shift = productionWorker.getShift();
		this.hourlyPayRate = productionWorker.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 += "\nEmployee Shift: " + shift + "\nEmployee Hourly Pay Rate: " + hourlyPayRate;
		return str;
	}
}


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 requiredTrainingHours  The employee's required training hours
	 * @param completedTrainingHours The employee's completed training hours
	 */
	public TeamLeader(String name, String number, String hireDate, int shift, double payRate, double monthlyBonus,
			double requiredTrainingHours, double completedTrainingHours) {
		super(name, number, hireDate, shift, payRate);
		this.monthlyBonus = monthlyBonus;
		this.requiredTrainingHours = requiredTrainingHours;
		this.completedTrainingHours = completedTrainingHours;
	}


	/**
	 * 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 += "\nEmployee Monthly Bonus: " + monthlyBonus + "\nEmployee Required Training Hours: "
				+ requiredTrainingHours + "\nEmployee Completed Training Hours: " + completedTrainingHours;
		return str;
	}


}


class App {


	public static void main(String[] args) {
		// create a new basic employee object
		Employee employee = new Employee("Dominic Giglio", "123-A", "01/25/2022");


		// print out the basic employee object
		System.out.println("\nThis is a basic employee object: ");
		System.out.println(employee);


		// create a Production Worker object
		ProductionWorker productionWorker1 = new ProductionWorker("Michael Giglio", "456-B", "01/24/2022", 2, 30.00);


		// create a copy of the first Production Worker object
		ProductionWorker productionWorker2 = new ProductionWorker(productionWorker1);


		// print out the first Production Worker object
		System.out.println("\nThis is the first Production Worker object: ");
		System.out.println(productionWorker1);


		// print out the second Production Worker object
		System.out.println("\nThis is the second Production Worker object: ");
		System.out.println(productionWorker2);


		// create a Team Leader object
		TeamLeader teamLeader1 = new TeamLeader("Katie Proodian", "987-D", "01/10/2022", 1, 15.00, 1500, 100, 50);


		// create a copy of the first Team Leader object
		TeamLeader teamLeader2 = new TeamLeader(teamLeader1);


		// print out the first Team Leader object
		System.out.println("\nThis is the first Team Leader object: ");
		System.out.println(teamLeader1);


		// print out the second Team Leader object
		System.out.println("\nThis is the second Team Leader object: ");
		System.out.println(teamLeader2);
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS