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 have seen in one of the videos about inheritance. 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.
Using Python
In case of any query do comment. Thanks
Note: You did not mention anything about Employee class so assumed it is having name and Age as attribute. In case of any query do comment. I will help you further.
Code:
=========main.py=======
class Employee:
#constructor
def __init__(self,name,age):
self.name = name
self.age = age
#accessors
def getName(self):
return self.name
def getAge(self):
return self.age
#mutators
def setName(self,name):
self.name = name
def setAge(self,age):
self.age = age
def __str__(self):
return "Name: {}, Age: {}".format(self.name,self.age)
#derived class ShiftSupervisor
class ShiftSupervisor(Employee):
#constructor
def __init__(self,name,age,annualSalary,annualProductionBonus):
super().__init__(name,age) #calling super class constructor
self.annualSalary = annualSalary
self.annualProductionBonus = annualProductionBonus
#accessors
def getAnnualSalary(self):
return self.annualSalary
def getAnnualProductionBonus(self):
return self.annualProductionBonus
#mutators
def setAnnualSalary(self,salary):
self.annualSalary = salary
def setAnnualProductionBonus(self,bonus):
self.annualProductionBonus = bonus
def __str__(self):
return "{}, Salary: {:.2f}, Production Bonus: {:.2f}".format(super().__str__(),self.annualSalary,self.annualProductionBonus)
#main driver program
#create an object of ShiftSupervisor and display it
emp1 = ShiftSupervisor("Alex",28,50000,2000)
print(emp1)
========Screen shot of the code for indentation======
output:
Get Answers For Free
Most questions answered within 1 hours.