Question: Starter code: class Worker: #Constructor def _ _ init _ _ ( self ) : self.employee _ number = None self.office _ number = None
Starter code:
class Worker:
#Constructor
def initself:
self.employeenumber None
self.officenumber None
self.name None
self.birthdate None
self.totalhoursworked
self.totalovertimehours
self.overtimesalary None
self.hourlysalary None
#Gets employee number
def getemployeenumberself:
return self.employeenumber
#Sets employee number
def setemployeenumberself x:
self.employeenumber x
#Gets office number
def getofficenumberself:
return self.officenumber
#Sets office number
def setofficenumberself x:
if x or x :
return False
else:
self.officenumber x
return True
#Gets name
def getnameself:
return self.name
#Sets name
def setnameself x:
self.name x
#Gets birthdate
def getbirthdateself:
return self.birthdate
#Sets birthdate
def setbirthdateself m d y:
if m or m or d or d :
return False
else:
self.birthdate m d y
return True
#Get hours worked
def gethoursworkedself:
return self.totalhoursworked
#Add to hours worked total
def addhoursself x:
if x :
self.totalhoursworked
self.totalovertimehours x
else:
self.totalhoursworked x
#Gets hours worked overtime
def gethoursovertimeself:
return self.totalovertimehours
#Sets hourly salary
def sethourlysalaryself x:
if x :
return False
else:
self.hourlysalary x
return True
#Sets overtime hourly salary
def setovertimesalaryself x:
if x :
return False
else:
self.overtimehourlysalary x
return True
#Gets hourly salary
def gethourlysalaryself:
return self.hourlysalary
#Gets overtime hourly salary
def getovertimesalaryself:
return self.overtimehourlysalary
#Gets pay
def getpayself:
return selftotalhoursworked self.hourlysalaryselftotalovertimehours self.overtimehourlysalary
Assignment:
For this lab you will modify your Lab to make several improvements to the gettersetter
methods. Instead of having them return TrueFalse modify each one to throw an exception if
invalid data is passed.
Modify these methods in the following way:
addhoursx
o If the number of hours being added is less than throw an exception. Do not
change how the hours are distributed if the number of hours added is greater
than
setemployeenumberx
o The employee number must be an integer. If the given input is not an integer,
throw an exception
setofficenumberx
o If the office number given is less than or greater than throw an
exception.
setnamex
o If the given name is empty, throw an exception
o Any of the following characters should be removed from the name:
Underscore period, and dash
setbirthdatem d y
o If the given value for the month is less than or greater than throw an
exception
o If the given value for the day is less than or greater than throw a different
exception
You do not need to round or truncate your output. Name your class Worker and save your
program as Labpy
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
