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: str, number: int):
self.name = name
self.number = number
def get_name(self):
print(f'Name: {self.name}')
def get_number(self):
print(f'Number: {self.number}')
def set_new_name(self):
self.name = input('Input new name: ')
def set_new_number(self):
self.number = int(input('Input new number: '))
class ProductionWorker(Employee):
def __init__(self, name, number, shift_number: int, pay_rate: float):
super().__init__(name, number)
self.shift_number = shift_number
self.pay_rate = pay_rate
def get_shift(self):
if self.shift_number == 1:
print('Night shift')
elif self.shift_number == 2:
print('Day shift')
else:
print('Invalid shift number')
def get_pay_rate(self):
print(f'Hourly pay rate: {self.pay_rate} dollars/hour')
def set_new_shift(self):
self.shift_number = int('Input new shift number (1 or 2): ')
def set_new_pay_rate(self):
self.pay_rate = int('Input new Hourly pay rate: ')
Comments
Leave a comment