Question

Python 3 Question Please keep the code introductory friendly and include comments. Many thanks. Prompt: The...

Python 3 Question

Please keep the code introductory friendly and include comments. Many thanks.

Prompt:

The owners of the Annan Supermarket would like to have a program that computes the weekly gross pay of their employees. The user will enter an employee’s first name, last name, the hourly rate of pay, and the number of hours worked for the week. In addition, Annan Supermarkets would like the program to compute the employee’s net pay and overtime pay. Overtime hours, any hours over 40, are paid at 1.5 the regular hourly rate. Net pay is gross pay minus taxes (Refer to the tax table below).

Define a class called Employee. The class must have private attributes to store the employee's name, hourly rate, and regular (≤ 40) and overtime hours worked. The class must also have methods to perform the following tasks:

--A constructor to initialize the hourly rate to the minimum wage of $7.25 per hour and the hours worked (regular and overtime) to 0.0.

--A method (setter/mutator) to get:

the employee's name, the hourly rate, the hours worked for the month (by the week, assume 4 weeks in a month)

(do not write separate setters for regular and overtime work hours)

--A method(getter/accessor) to return

the employee's name, the hourly rate, the total regular hours worked for the month, and the total overtime hours worked for the month

--A method(getter/accessor) to return

monthly regular pay

--A method(getter/accessor) to return

monthly overtime pay

--A __str__ method to display the output, which must include the following information:

employee's name, total regular hours worked, total overtime hours worked, total hours worked, pay rate, monthly regular pay, monthly overtime pay, monthly gross pay, monthly taxes, and monthly net pay

Write a main function that declares an object for the class defined and test the functions and methods written for the class. Allow the user to run the program as many times as possible. No input, processing, or output should happen in the main function. All work should be delegated to other functions. Include the recommended minimum documentation for each function.

(This is the tax table)

Bracket If gross pay over But not over Tax
1 $0.00 $2,000.00 10%
2 $2,000.00 $3,500.00 15%
3 $3,500.00 $6,000.00 28%
4 $6,000.00 $10,000.00 31%
5 $10,000.00 N/A 36%

Run the program using:

John Doe

$35.10

40,30,40,35

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#please provide a comment why a down vote since it is affecting my CF score
#I would definitely try to solve your issue

class Employee:
def __init__(self): #constructor to assign initial values
self.wage_per_hour = 7.25 #minimum wage
self.regular_hours = 0 #minimum regular hours
self.overtime_hours = 0 #minimum overtime hours
def setDetails(self,name,hourly_rate,hours_worked_list): #sets the details and sets the regular and overtime hours
self.name = name
self.wage_per_hour = hourly_rate
total_hours = sum(hours_worked_list) #sum(list) of hours
if total_hours > 160: # 160 since 4 weeks and every week upto 40 is for regular hence 4*40 = 160
self.regular_hours = 160 #assign 160 and rest is overtime
self.overtime_hours = total_hours - 160
else:
self.regular_hours = total_hours
def getDetails(self): #returns a list of details of the employee
li_ = [self.name,self.wage_per_hour,self.regular_hours,self.overtime_hours]
return li_
def getMonthlyRegularPay(self): #returns the monthly regular pay
return self.wage_per_hour * self.regular_hours
def getMonthlyOvertimePay(self):
return self.wage_per_hour * self.overtime_hours * 1.5 #returns the monthly overtime pay
def __str__(self):
self.calculate() # responsible for all the gross_payment and net_payment
string = str("\nEmployee Name: \t"+str(self.name)+ #returns string to print()
"\nTotal Regular Hours Worked: \t"+str(self.regular_hours)+
"\nTotal Overtime Hours Worked:\t"+str(self.overtime_hours)+
"\nTotal Hours Worked: \t"+str(self.regular_hours + self.overtime_hours)+
"\nMonthly Gross Pay: \t"+str(self.gross_pay)+
"\nMonthly Taxes: \t"+str(self.tax)+"%"+
"\nMonthly Net Pay: \t"+str(self.net_pay))
return string
def calculate(self): #calculates the gross_pay and net_pay
self.gross_pay = self.getMonthlyOvertimePay() + self.getMonthlyRegularPay() #getting monthlt regular and overtime pay
if self.gross_pay >= 0.00 and self.gross_pay < 2000.00: #selecting tax using if else
self.tax = 10
elif self.gross_pay >= 2000.00 and self.gross_pay < 3500.00:
self.tax = 15
elif self.gross_pay >= 3500.00 and self.gross_pay < 6000.00:
self.tax = 28
elif self.gross_pay >= 6000.00 and self.gross_pay < 10000.00:
self.tax = 31
elif self.gross_pay >= 10000.00:
self.tax = 36
self.net_pay = self.gross_pay - (self.gross_pay*self.tax/100) #assign net_pay
def handle_main(e): #responsible to run the whole program
while True:
try:
print("\n------------------------------------")
li_ = []
name = input("Enter the name: ")
hourly_rate = float(input("Enter the hourly rate: "))
li_.append(int(input("Enter hours worked in week:1 ")))
li_.append(int(input("Enter hours worked in week:2 ")))
li_.append(int(input("Enter hours worked in week:3 ")))
li_.append(int(input("Enter hours worked in week:4 ")))
e.setDetails(name,hourly_rate,li_)
print(e)
print("------------------------------------")
in_put = input("\nDo you wish to continue?\nEnter 'y' to continue: ")
if in_put != 'y':
print("Quitting...")
break
except Exception as e:
print("\nSomething went wrong..... input again.")
e = Employee() #creating an object in main
handle_main(e) #only one function which handles everything else
#No input or processing or output is done inside MAIN

class Employee: def _init_(self): #constructor to assign initial values self.wage_per_hour = 7.25 #minimum wage self.regular_

def calculate(self): #calculates the gross_pay and net_pay self-gross_pay self.getMonthlyOvertimePay() + self.getMonthlyRegulEnter the name: John Enter the hourly rate: 37.5 Enter hours worked in week:1 40 Enter hours worked in week:2 35 Enter hours

class Employee: def _init_(self): #constructor to assign initial values self.wage_per_hour = 7.25 #minimum wage self.regular_hours = #minimum regular hours self.overtime_hours = #minimum overtime hours def setDetails(self,name, hourly rate, hours_worked_list): #sets the details and sets the regular and overtime hours self.name = name self.wage_per_hour = hourly rate total_hours = sum(hours_worked_list) #sum(List) of hours if total_hours > 160: # 160 since 4 weeks and every week upto 40 is for regular hence 4*40 = 160 self.regular_hours = 160 #assign 160 and rest is overtime self.overtime_hours = total_hours - 160 else: self.regular_hours = total_hours def getDetails(self): #returns a list of details of the employee li_ = [self.name, self.wage_per_hour, self.regular_hours, self.overtime_hours ] return li_ def getMonthlyRegularPay(self): #returns the monthly regular pay return self.wage_per_hour * self.regular_hours def getMonthlyOvertimePay(self): return self.wage_per_hour self.overtime_hours * 1.5 #returns the monthly overtime pay def str_(self): self.calculate() # responsible for all the gross_payment and net_payment string = str("\nEmployee Name: \t"+str(self.name)+ #returns string to print() "\nTotal Regular Hours Worked: \t"+str(self.regular_hours)+ "\nTotal Overtime Hours Worked:\t"+str(self.overtime_hours)+ "\nTotal Hours Worked: \t"+str(self.regular_hours + self.overtime_hours)+ "\nMonthly Gross Pay: \t"+str(self.gross_pay)+ "\nMonthly Taxes: \t"+str(self.tax)+"%"+ "\nMonthly Net Pay: \t"+str(self.net_pay)) return string def calculate(self): #calculates the gross_pay and net_pay self.gross_pay = self.getMonthlyOvertimePay() + self.getMonthlyRegularPay() #getting monthlt regular and overtime pay if self.gross_pay >= 0.00 and self.gross_pay < 2000.00: #selecting tax using if else self.tax = 10 elif self.gross_pay >= 2000.00 and self-gross_pay < 3500.00: self.tax = 15 elif self.gross_pay >= 3500.00 and self.gross_pay < 6000.00: self.tax = 28 elif self.gross_pay >= 6000.00 and self.gross_pay < 10000.00:

def calculate(self): #calculates the gross_pay and net_pay self-gross_pay self.getMonthlyOvertimePay() + self.getMonthlyRegularPay() #getting monthlt regular and overtime pay if self.gross_pay >= 0.00 and self.gross_pay < 2000.00: #selecting tax using if else self.tax = 10 elif self.gross_pay >= 2000.00 and self.gross_pay < 3500.00: self.tax = 15 elif self.gross_pay >= 3500.00 and self.gross_pay < 6000.00: self.tax = 28 elif self.gross_pay >= 6000.00 and self-gross_pay < 10000.00: self.tax = 31 elif self.gross_pay >= 10000.00: self.tax = 36 self.net_pay = self.gross_pay - (self.gross_pay*self.tax/100) #assign net_pay def handle_main(e): #responsible to run the whole program while True: try: print("\n :) li_ = [] name input("Enter the name: ") hourly_rate float(input("Enter the hourly rate: ")) li_.append(int(input("Enter hours worked in week:1 ")) li_.append(int(input("Enter hours worked in week:2 ")))) li_.append(int(input("Enter hours worked in week:3 "))) li_.append(int(input("Enter hours worked in week:4 "))) e.setDetails(name, hourly rate,li_) print(e) print in_put = input("\nDo you wish to continue?\nEnter 'y' to continue: ") if in_put != 'y': print("Quitting...") break except Exception as e: print("\nSomething went wrong..... input again.") e = Employee() #creating an object in main handle_main(e) #only one function which handles everything else #No input or processing or output is done inside MAIN ") Enter the name: John Enter the hourly rate: 37.5

Enter the name: John Enter the hourly rate: 37.5 Enter hours worked in week:1 40 Enter hours worked in week:2 35 Enter hours worked in week:3 49 Enter hours worked in week:4 35 John 150 Employee Name: Total Regular Hours Worked: Total Overtime Hours Worked: Total Hours Worked: Monthly Gross Pay: Monthly Taxes: Monthly Net Pay: 150 5625.0 28% 4050.0 Do you wish to continue? Enter 'y' to continue: y Enter the name: Harry Enter the hourly rate: 55.5 Enter hours worked in week:1 10 Enter hours worked in week:2 20 Enter hours worked in week:3 15 Enter hours worked in week:4 10 Employee Name: Total Regular Hours Worked: Total Overtime Hours Worked: Total Hours Worked: Monthly Gross Pay: Monthly Taxes: Monthly Net Pay: Harry 55 0 55 3052.5 15% 2594.625 Do you wish to continue? Enter 'y' to continue: n Quitting...

Add a comment
Know the answer?
Add Answer to:
Python 3 Question Please keep the code introductory friendly and include comments. Many thanks. Prompt: The...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • THIS IS WHAT I HAVE I NEED TO FIX IT SO: hours_worked should not be inputed...

    THIS IS WHAT I HAVE I NEED TO FIX IT SO: hours_worked should not be inputed separately. Get the hours as 40 40 40 40 or 40, 40, 40, 40 whichever separator suits you. How do I do this? How would you change what I have in to it getting into that kind of input. Thank you! class Employee: again = 'y' def __init__(self): self.__rate = 7.25 self.__totalhour = 0 self.__regularpay = 0 self.__overtimepay = 0 self.__totalpay = 0 self.__tax...

  • Design a program(Creating a RAPTOR flowchart) that will read a file of employee records containing employee...

    Design a program(Creating a RAPTOR flowchart) that will read a file of employee records containing employee number, employee name, hourly pay rate, regular hours worked and overtime hours worked. The company pays its employees weekly, according to the following rules: regular pay = regular hours worked × hourly rate of pay overtime pay = overtime hours worked × hourly rate of pay × 1.5 total pay = regular pay + overtime pay Your program is to read the input data...

  • By editing the code below to include composition, enums, toString; must do the following: Prompt the...

    By editing the code below to include composition, enums, toString; must do the following: Prompt the user to enter their birth date and hire date (see Fig. 8.7, 8.8 and 8.9 examples) in addition to the previous user input Create a new class that validates the dates that are input (can copy date class from the book) Incorporate composition into your class with these dates Use enums to identify the employee status as fulltime (40 or more hours worked for...

  • Introduction to computer class, Java programming through eclipse: Ue the following criteria to create the code:...

    Introduction to computer class, Java programming through eclipse: Ue the following criteria to create the code: SALARY Input first and last name - Output the names last, first in your output - Make the federal withholding rate a constant 20% (not an input value) No state tax Generate two new values: regular pay and overtime pay - 40 hours workedor less - Regular pay is pay rate * hours worked - Overtime pay is 0 Otherwise - Regular pay is...

  • RUN THIS PROGRAM ON NETBEANS As a Software Developer, you have received a requirement from a Company to implement a prot...

    RUN THIS PROGRAM ON NETBEANS As a Software Developer, you have received a requirement from a Company to implement a prototype for its payroll system. You receive the following specifications: If an employee works more than its regular hours, it is considered overtime and it will be paid based on the employee’s experience. All employees are paid biweekly (80 hours) Employee taxes: 1% This company manages three categories of workers based on employee’s experience. Group 1 (Silver) o Pay rate:...

  • Given attached you will find a file from Programming Challenge 5 of chapter 6 with required...

    Given attached you will find a file from Programming Challenge 5 of chapter 6 with required you to write a Payroll class that calculates an employee’s payroll. Write exception classes for the following error conditions: An empty string is given for the employee’s name. An invalid value is given to the employee’s ID number. If you implemented this field as a string, then an empty string could be invalid. If you implemented this field as a numeric variable, then a...

  • write in java and please code the four classes with the requirements instructed You will be...

    write in java and please code the four classes with the requirements instructed You will be writing a multiclass user management system using the java. Create a program that implements a minimum of four classes. The classes must include: 1. Employee Class with the attributes of Employee ID, First Name, Middle Initial, Last Name, Date of Employment. 2. Employee Type Class that has two instances of EmployeeType objects: salaried and hourly. Each object will have methods that calculates employees payrol...

  • java Payroll class Exceptions Programming Challenge 5 of Chapter 6 required you to write a Payroll...

    java Payroll class Exceptions Programming Challenge 5 of Chapter 6 required you to write a Payroll class that calculates an employee’s payroll. Write exception classes for the following error conditions: • An empty string is given for the employee’s name. • An invalid value is given for the employee’s ID number. If you implemented this field as a string, then an empty string would be invalid. If you implemented this field as a numeric variable, then a negative number or...

  • I would like help and there are three different classes in the coding.. 14.11 Prog11 Inheritance(PayrollOvertime)...

    I would like help and there are three different classes in the coding.. 14.11 Prog11 Inheritance(PayrollOvertime) Create three files to submit: • Payroll class.java -Base class definition • PayrollOvertime.jave - Derived class definition • ClientClass.java - contains main() method Implement the two user define classes with the following specifications: Payroll class (the base class) (4 pts) • 5 data fields(protected) o String name - Initialized in default constructor to "John Doe" o int ID - Initialized in default constructor to...

  • a) Calculate the Overtime Hours (Column F). The formula for Overtime Hours is based on each...

    a) Calculate the Overtime Hours (Column F). The formula for Overtime Hours is based on each employee’s Total Hours Worked and is dependent on which department the employee works in. If the Total Hours Worked (column D) is greater than the assigned hours designated by the employee’s department (as listed in the table on rows 24 and 25), then the Overtime Hours is the Total Hours Worked minus the assigned hours. If the employee’ Total Hours Worked are less than...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT