1.Write an Employee class that keeps data attributes for the following pieces of information:
a. Employee name
b. Employee number Next, write a class named ProductionWorker that is a subclass of the Employee class. The ProductionWorker class should keep data attributes for the following information:
c. Shift number (an integer, such as1 for morning shift, 2 for evening shift)
d. Hourly pay rate Write the appropriate accessor and mutator methods for each class
class Employee:
def __init__(self, name, number):
self.__name = name
self.__employee_number = number
def set_name(self, name):
self.__name = name
def set_employee_number(self, number):
self.__employee_number = number
def get_name(self):
return self.__name
def get_employee_number(self):
return self.__employee_number
class ProductionWorker(Employee):
def __init__(self, nume, number, shift_number, hourly_pay):
if shift_number == 1 or shift_number == 2:
self.__shift = shift_number
else:
raise ValueError('The shift number should either be 1 or 2.')
self.__hourly_pay = float(hourly_pay)
Employee.__init__(self, name, number)
def set_shift_number(self, shift_number):
if shift_number == 1 or shift_number == 2:
self.__shift == shift_number
else:
raise ValueError('The shift number should either be 1 or 2.')
def set_hourly_pay(self, hourly_pay):
self.__hourly_pay = float(hourly_pay)
def get_shift(self):
if self.__shift == 1:
return 'day'
else:
return 'night'
def get_hourly_pay(self):
return format(self.__hourly_pay, ',.2f')
Comments
Leave a comment