Python program assigment with details Write an Employee class that keeps data at
ID: 3872281 • Letter: P
Question
Python program assigment with details
Write an Employee class that keeps data attributes for the following pieces of information:
Employee Name
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:
Shift Number (an integer 1 or 2)
Hourly Pay Rate
The workday is divided into two shifts: day and night. The shift attribute will hold an integer value representing the shift that the employee works. The day shift is shift 1 and the night shift is shift 2. Write the appropriate accessor and mutator methods for each class.
Once you have written the classes, write a program that creates an object of the ProductionWorker class and prompts the user to enter data for each of the object’s data attributes. Store the data in the object and then use the object’s accessor methods to retrieve it and display it on the screen.
Add an __str__ method to the ProductionWorker class that will print the attributes from both classes in a readable format. In the main part of the program, create one more ProductionWorker object, assign values to the attributes and print both objects using the print statement.
Explanation / Answer
class Employee:
def __init__(self,name,number):
self.__name = name
self.number = number
def set_emp_name(self,name):
self.__name = name
def set_emp_number(self,number):
self.__number = number
def get_emp_name(self):
return self.__name
def get_emp_number(self):
return self.number
class ProductionWorker(Employee):
def __init__(self,name,number,shift_num,pay_rate):
Employee.__init__(self,name,number)
self.__shift_num = shift_num
self.__pay_rate = pay_rate
def set_shift_num(self,shift_num):
self.__shift_num = shift_num
def set_pay_rate(self,pay_rate):
self.__pay_rate = pay_rate
def get_shift_num(self):
return self.__shift_num
def get_pay_rates(self):
return self.__pay_rate
def main():
print('enter following Details of the Employee')
emp_name = input('Enter Employee Name: ')
number = input('Enter Employee Number: ')
sh = input('Enter Shift Number: ')
pay = input('Enter Pay Rate: ')
emp = ProductionWorker(emp_name, number, sh, pay)
print ('Details of Employee:')
print ('Name',emp.get_emp_name())
print ('Employee Number',emp.get_emp_number())
print ('Shift Number',emp.get_shift_num())
print ('Pay Rate',emp.get_pay_rates())
if __name__ == '__main__':
main()
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.