The problem reads as follows: In a particular factory, a team leader is an hourl
ID: 3625379 • Letter: T
Question
The problem reads as follows:
In a particular factory, a team leader is an hourly paid production worker who leads a small team. In addition to hourly pay, team leaders earn a fixed monthly bonus. Team leaders are required to attend a minimum amount of hours of training per year. Design a TeamLeader class that inherits from the ProductionWorker class you designed in Programming Challenge 1. 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.
Thanks in advance for your assistance.
Explanation / Answer
import java.io.*;
import java.util.Scanner;
class Employee
{
//fields
private String Empname;
private String Empnumber;
private String Hiredate;
// default constructor
public Employee()
{
Empname=" ";
Empnumber=" ";
Hiredate=" ";
}
//parameterized constructor
public Employee(String Empname,String Empnumber,
String Hiredate)
{
setName(Empname);
setNumber(Empnumber);
setHireDate(Hiredate);
}
//Mutator functions
//sets employee name
public void setName(String n)
{
Empname = n;
}
//sets employee number
public void setNumber(String num)
{
Empnumber = num;
}
//sets hire date
public void setHireDate(String h)
{
Hiredate = h;
}
/* Accessor functions */
//returns employee name
public String getName()
{
return Empname;
}
//returns employee number
public String getNumber()
{
return Empnumber;
}
//returns hire date
public String getHireDate()
{
return Hiredate;
}
}
class ProductionWorker extends Employee
{
//fields
private int shift;
private double hourpayrate;
//constructor
public ProductionWorker(String Empname,
String Empnumber,
String Hiredate,int shift,
double hourpayrate)
{
super(Empname,Empnumber,Hiredate);
setShift(shift);
setHourlyPayRate(hourpayrate);
}
//accessor
public int getShift()
{
return shift;
}
public double getHourlyPayRate()
{
return hourpayrate;
}
//mutator
public void setShift(int s)
{
shift = s;
}
public void setHourlyPayRate(double r)
{
hourpayrate = r;
}
}
class TeamLeader extends ProductionWorker
{
private int train_hours;
private int min_hours;
private double bonus;
TeamLeader(String Empname,String Empnumber,
String Hiredate,int shift,double hourpayrate)
{
super(Empname,Empnumber,Hiredate,shift,hourpayrate);
}
public void setBonus(double bo)
{
if(train_hours>=min_hours)
bonus=bo;
else
bonus=0;
}
public void setMinimumHours(int hrs)
{
min_hours=hrs;
}
public int getMinimumHours()
{
return min_hours;
}
public double getBonus()
{
return bonus;
}
public void setTrainHours(int hrs)
{
train_hours=hrs;
}
public int getTrainHours()
{
return train_hours;
}
}
public class employeeDemo //emp
{
public static void main(String[] args)
{
String name,id,date;
double pay;
int shift;
//create scanner object
Scanner keyboard= new Scanner(System.in);
//inputing data
System.out.println("Enter employee name:");
name=keyboard.nextLine();
//inputting ID
System.out.println("Enter employee ID: ");
id=keyboard.nextLine();
//inputting date
System.out.println("Enter employee Date: ");
date=keyboard.nextLine();
//inputting shift
System.out.println("1-Day Shift 2-Night shift");
System.out.println("Enter employee Shift: ");
shift=keyboard.nextInt();
//inputting pay
System.out.println("Enter hourly pay:");
pay=keyboard.nextDouble();
//instantiating worker
TeamLeader TL = new
TeamLeader(name,id,date,shift,pay);
TL.setBonus(5000);
TL.setTrainHours(20);
TL.setMinimumHours(19);
//outputting data using accessor methods
System.out.println("Employee Name:"
+ TL.getName());
System.out.println("Employee ID:"
+ TL.getNumber());
System.out.println("Hire Date:"
+ TL.getHireDate());
System.out.println("Shift:"+ TL.getShift());
System.out.println("Hourly Rate:"
+ TL.getHourlyPayRate());
System.out.println("Bonus:$"+TL.getBonus());
}//end main
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.