I'm attempting to write a program with subclasses. I've been debugging for hours and can't find a solution.
I'm need to write an Employee class that keeps data attributes for Employee name and Employee number. Next, I need to write a class named ProductionWorker that is a subclass of the Employee class. The ProductionWorker class should keep data attributes for Shift number, Hourly pay rate, and Hours worked this week. 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 1 and the night shift is 2. Write the appropriate accessor and mutator methods for each class.
Next, I need to create an object of the ProductionWorker class and prompts the user to enter data for each of the object’s data attributes. I use a data validation class to make sure the user enters valid values for pay rate and hours. I Store the data in the object and then use the object’s accessor methods to retrieve it and display it on the screen. I need to also display this worker’s total pay for the week. Total pay = hourly rate * hours worked. I can't do any calculations on the main file.
Next, I need to write a ShiftSupervisor class that is a separate subclass of the Employee class. Shift supervisors earn a salary and a yearly bonus if their shift meets production goals. 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.
I need to write a second program that will create an object of the ShiftSupervisor class and prompt the user to enter data for each of the object’s data attributes. I need to display this supervisor’s total annual pay.
When I run the main file I get this error:
Traceback (most recent call last):
File "/Users/Jeremy/Documents/Python Projects/Mosier_Jeremy_HW8/HW8MAIN.py", line 4, in <module>
employeeObject = EmployeeFile.ProductionWorker ()
TypeError: __init__() missing 5 required positional arguments: 'name', 'number', 'shift', 'rate', and 'hours'
Here is my ValidationFile:
class ValidationClass:
def checkFloat (self, inputString):
try:
result = float (inputString)
except Exception:
return -1
if result < 0:
return -1
else:
return result
def checkInteger (self, inputString):
try:
result = int (inputString)
except Exception:
return -1
if result < 0:
return -1
else:
return result
Here is my EmployeeFile:
class Employee ():
def __init__(self, name, number):
self.__Name = name
self.__Number = number
def set_Name (self, name):
self.__Name = value
def set_Number(self, number):
self.__Number = value
def get_Name (self):
return self.__Name
def get_Number (self):
return self.__Number
class ProductionWorker (Employee):
def __init__(self, name, number, shift, rate, hours):
self.__Shift = shift
self.__Rate = rate
self.__Hours = hours
Employee.__init__(self, name, number)
def set_Shift (self, shift):
self.__Shift = shift
def set_PayRate (self, rate):
self.__PayRate = rate
def set_Hours (self, hours):
self.__Hours = hours
def get_Shift (self):
if self.__Shift == 1:
s = 'Day shift'
elif self.__Shift == 2:
s = 'Night shift'
return s
def get_PayRate (self):
return self.__PayRate
def get_Hours (self):
return self.__Hours
def get_Pay (self):
return self.__Pay
def calcPay (self):
self.__Pay = (self.__PayRate) * (self.__Hours)
class ShiftSupervisor (Employee):
def __init__ (self, name, number, salary, bonus):
self.__Salary = salary
self.__Bonus = bonus
Employee.__init__ (self, name, number)
def set_Salary (self, salary):
return self.__Salary
def set_Bonus (self, bonus):
return self.__Bonus
def get_Salary (self):
self.__Salary = salary
def get_Bonus (self):
self.__Bonus = bonus
def calcPay (self):
self.__Pay = (self.__Salary) + (self.__Bonus)
Here is my main file:
import EmployeeFile
import ValidationFile
employeeObject = EmployeeFile.ProductionWorker ()
validationObject = ValidationFile.ValidationClass ()
employeeName = -1
while employeeName == -1:
employeeName = input ('Please enter the employee name: ')
if employeeName == '':
print ('ERROR: Please enter a valid name.')
employeeName = -1
employeeNumber = -1
while employeeNumber == -1:
employeeNumber = input ('Please enter the employee name: ')
if employeeNumber == '':
print ('ERROR: Please enter a valid name.')
employeeNumber = -1
shiftNumber = -1
while shiftNumber == -1:
shiftNumber = input ('Please enter which shift the employee works. 1 for day shift, 2 for night shift: ')
if shiftNumber < 1 or shiftNumber > 2:
print ('ERROR: Shift number must be entered as a 1 or a 2.')
payRate = -1
while payRate == -1:
payEntry = input ('Please enter which shift the employee works. 1 for day shift, 2 for night shift: ')
payRate = validationObject.checkFloat (payEntry)
if payRate == -1:
print ('ERROR: Pleae enter a valid payRate.')
hours = -1
while hours == -1:
hoursEntry = input ('Please enter which shift the employee works. 1 for day shift, 2 for night shift: ')
payRate = validationObject.checkFloat (hoursEntry)
if payRate == -1:
print ('ERROR: Pleae enter a valid payRate.')
#populate inputs
employeeObject.set_Name (employeeName)
employeeObject.set_Number (employeeNumber)
employeeObject.set_Shift (shiftNumber)
employeeObject.set_PayRate (payRate)
employeeObject.set_Hours (hours)
print ('Employee name: ', employeeName)
print ('Employee number: ', employeeNumber)
print ('Shift: ', shiftNumber)
print ('Pay rate: ', payRate)
print ('Hours worked: ', hours)