Data Structures
Running Head: PROGRAM ASSIGNMENT 03
2
PROGRAM ASSIGNMENT 03
Program Assignment 03 Student Name Course Title Instructor Institution Affiliation Date
Introduction
This program assignment involves creation of employee class and production_worker subclass that will store some objects for the employees. The employee class contains the employee name and employee number while the production worker is a subclass with shift number and hourly pay rate attributes. The program prompts the user to enter the attribute values for production worker subclass as follows:
Source code for Printing
Name: Your Name
Class and Section: CS 222 01
Assignment: Program Assignment 02
Due Date: See above
Date Turned in:
import sys
class Employee ():
def __init__(self, name, number):
self.__Name = name
self.__Number = number
defset_Name (self, name):
self.__Name = value
defset_Number(self, number):
self.__Number = value
defget_Name (self):
returnself.__Name
defget_Number (self):
returnself.__Number
classProductionWorker (Employee):
def __init__(self, name, number, rate,shift,hours):
self.Shift= shift
self.Rate= rate
self.Hours= hours
Employee.__init__(self, name, number)
defset_PayRate (self, rate):
self.PayRate = rate
defset_Shift (self, shift):
self.Shift = shift
defset_Hours (self, hours):
self.Hours = hours
defget_Shift (self):
ifself.Shift == 1:
s = 'Day shift'
elifself.Shift == 2:
s = 'Night shift'
return s
defget_PayRate (self):
returnself.PayRate
defget_Hours (self):
returnself.Hours
employeeObject=ProductionWorker()employee_Name=-1whileemployee_Name==-1:employee_Name= input ('Please enter the employee name: ')ifemployee_Name=='':print('ERROR: Please enter a valid name.')employee_Name=-1employeeNumber=-1whileemployeeNumber==-1:employee_Number= input (Enter the name of Employee: ')ifemployee_Number=='':print('ERROR: Invalid Employee Name.')employee_Number=-1shift_Number=-1whileshift_Number==-1:shift_Number= input (‘Enter employee shift. 1 for day shift, 2 for night shift: ')ifshift_Number<1orshift_Number>2:print('ERROR: Shift number should be either 1 or 2')hourly_PayRate=-1whilehourly_PayRate==-1:pay_Entry= input ('Please enter which shift the employee works. 1 for day shift, 2 for night shift: ')hourly_PayRate=validationObject.checkFloat(pay_Entry)ifhourly_PayRate==-1:print('ERROR: Pleae enter a valid hourly_PayRate.')hours=-1while hours ==-1:hoursEntry= input ('Please enter which shift the employee works. 1 for day shift, 2 for night shift: ')hourly_PayRate=validationObject.checkFloat(hoursEntry)ifhourly_PayRate==-1:print('ERROR: Pleae enter a valid hourly_PayRate.')#saving the objects in the respective classesemployeeObject.set_Name(employee_Name)employeeObject.set_Number(employee_Number)employeeObject.set_Shift(shift_Number)employeeObject.set_Hourly_PayRate(hourly_PayRate)employeeObject.set_Hours(hours)print('Employee Name Entered: ',employee_Name)print('Employee Number Entered: ',employee_Number)print('Shift Number: ',shift_Number)print('Employee Pay Rate: ',hourly_PayRate)print('Number of Hours Worked: ', hours)