In a particular factory a shift supervisor is a salaried emp
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 extends the Employee class you created in Programming Challenge 1. 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. Demonstrate the class by writing a program that uses a ShiftSupervisor object.
This is in java
I am a beginner , the comments are appreciated but not needed , thanks
Solution
Test Employee Class:
public class Employee {
private String name;
private String department;
public Employee(String name, String department) {
super();
this.name = name;
this.department = department;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
}
SUPERVISOR CLASS:
public class ShiftSupervisor extends Employee {
private float salary;
private float bonus;
public ShiftSupervisor(String name, String department, float salary,
float bonus) {
super(name, department);
this.salary = salary;
this.bonus = bonus;
}
public float getSalary() {
return salary;
}
public void setSalary(float salary) {
this.salary = salary;
}
public float getBonus() {
return bonus;
}
public void setBonus(float bonus) {
this.bonus = bonus;
}
@Override
public String toString() {
return \" Name=\"+getName()+\", Department=\"+getDepartment()+\", salary=$\" + salary + \", bonus=$\" + bonus;
}
}
DEMO:
public class DemoSupervisor {
public static void main(String[] args) {
// TODO Auto-generated method stub
ShiftSupervisor s1=new ShiftSupervisor(\"Jon\", \"Tech\", 25000f, 0f);
System.out.println(\"New Supervisor is:\"+s1.toString());
//Changing bonus to 1000
s1.setBonus(1000f);
System.out.println(\"\ Updated details:\"+s1.toString());
}
}

