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. Write a ShiftSupervisor class that is a subclass of the Employee class
you created in Programming Exercise 1. The ShiftSupervisor class should keep a data
attribute for the annual salary and a data attribute for the annual production bonus that a
shift supervisor has earned. Demonstrate the class by writing a program that uses a
ShiftSupervisor object.
ShiftSupervisor Class Program code:
# Employee class definition
class Employee:
def __init__(self, name, emp_number):
# Initialize data attributes
self.name = name
self.emp_number = emp_number
# Accessor methods
def get_name(self):
return self.name
def get_emp_number(self):
return self.emp_number
# Mutator methods
def set_name(self, name):
self.name = name
def set_emp_number(self, emp_number):
self.emp_number = emp_number
# ProductionWorker class definition, subclass of Employee
class ProductionWorker(Employee):
def __init__(self, name, emp_number, shift_number, hourly_pay_rate):
# Call superclass constructor to initialize inherited attributes
super().__init__(name, emp_number)
# Initialize additional data attributes
self.shift_number = shift_number
self.hourly_pay_rate = hourly_pay_rate
# Accessor methods
def get_shift_number(self):
return self.shift_number
def get_hourly_pay_rate(self):
return self.hourly_pay_rate
# Mutator methods
def set_shift_number(self, shift_number):
self.shift_number = shift_number
def set_hourly_pay_rate(self, hourly_pay_rate):
self.hourly_pay_rate = hourly_pay_rate
# ShiftSupervisor class definition, subclass of Employee
class ShiftSupervisor(Employee):
def __init__(self, name, emp_number, annual_salary, annual_production_bonus):
# Call superclass constructor to initialize inherited attributes
super().__init__(name, emp_number)
# Initialize additional data attributes
self.annual_salary = annual_salary
self.annual_production_bonus = annual_production_bonus
# Accessor methods
def get_annual_salary(self):
return self.annual_salary
def get_annual_production_bonus(self):
return self.annual_production_bonus
# Mutator methods
def set_annual_salary(self, annual_salary):
self.annual_salary = annual_salary
def set_annual_production_bonus(self, annual_production_bonus):
self.annual_production_bonus = annual_production_bonus
# Create an object of the ShiftSupervisor class and prompt the user to enter data
def main():
name = input("Enter shift supervisor name: ")
emp_number = input("Enter shift supervisor employee number: ")
annual_salary = float(input("Enter annual salary: "))
annual_production_bonus = float(input("Enter annual production bonus: "))
# Create ShiftSupervisor object
supervisor = ShiftSupervisor(name, emp_number, annual_salary, annual_production_bonus)
# Display the entered data using accessor methods
print("Shift Supervisor Name:", supervisor.get_name())
print("Shift Supervisor Employee Number:", supervisor.get_emp_number())
print("Annual Salary:", supervisor.get_annual_salary())
print("Annual Production Bonus:", supervisor.get_annual_production_bonus())
# Call the main function to start the program
if __name__ == "__main__":
main()
Executed Output:
Enter shift supervisor name: Peter
Enter shift supervisor employee number: 420
Enter annual salary: 500000
Enter annual production bonus: 10000
Shift Supervisor Name: Peter
Shift Supervisor Employee Number: 420
Annual Salary: 500000.0
Annual Production Bonus: 10000.0