The details are this, I need to make this class. It only says to make one class, Payroll. I should only be making what is stated.
Payroll class
The payroll class contains the following attributes:
Employee data containing many employees each made up of the following:
• employee name: string
• hours worked: float
• pay rate: float
• Total pay: float
The Payroll class has the following methods:
readData()
Reads a file of employee data (one employee / per line) with each line consisting of the following
fields with some type of delimiter between them. The data from the file is stored in the Payroll’s
attributes.
• name,
• hours,
• pay rate for each employee
The file may not exist the first time or it may exist and have data. Close the file after reading the
information into lists. Handle both cases.
Hint: You may use the split string function to break a line into name, hours, and pay rate.
writeData()
Writes the employee data in the Payroll’s attributes into a file listing each employee on a single
line with a delimiter between each field.
inputData()
The inputData method uses the classes attributes to store data. It has a loop, inside the loop are
statements to get the following data from the user:
• employee name – string
• hours worked – float
• pay rate – float
The loop repeats to read multiple employee information until a user indicates they no longer wish to
enter data.
Error checking is required to check the data to insure it does not corrupt the list(s).
computePay()
The computePay() method calculates the gross amount to be paid to each employee and save the
amount in the classes attributes:
a) For the first 40 hours, the rate is the given rate;
b) For hours over 40, the rate is 1.5 times the given rate
displayPay()
The method loops through the classes attributes to display a table in the following format:
DOODAD MANUFACTURING COMPANY JUNE PAYROLL
EMPLOYEE NAME HOURS WORKED PAY RATE GROSS PAY
Here is what I have, and I know it is wrong, but I am just lost. This is the last project of the class, and I am just so confused.
#payroll class
class payroll:
def __init__(self):
self.name = name
self.hours = hours
self.pay = pay
self.total = total
#set attributes
def set_name(self, name):
self.name = name
def set_hours(self, hours):
self.hours = hours
def set_pay(self, pay):
self.pay = pay
def set_total(self, hours, pay):
self.total = hours * pay
#return the attributes
def set_name(self, name):
return self.name
def set_hours(self):
return self.hours
def set_pay(self):
return self.pay
def set_total(self):
return self.total
zimmy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.