In: Computer Science
class employee:
name = str('')
hourlyWage=0
hoursWorked=0
def getPayment(self):
payment=self.hourlyWage*self.hoursWorked
return payment
class payrollApp(employee):
def printStatement(self):
print('The Employee Name is ' + self.name)
print('The Employee Hourly wage is ' + str(self.hourlyWage))
print('No of hours worked ' + str(self.hoursWorked))
print('The Employee payment is ' +
str(employee.getPayment(self)))
emp = []
x=0
a=True
totalPayout=0
while a:
emp.append(payrollApp())
emp[x].name=input("Enter Employee Name: ")
emp[x].hourlyWage=int(input("Enter hourly wage: "))
emp[x].hoursWorked=int(input("Enter No of hours worked: "))
totalPayout= totalPayout + (emp[x].hourlyWage *
emp[x].hoursWorked)
print("\n")
x=x+1
b=input("Do you want to enter new employee yes or no ")
print('\n')
if b=='no':
a=False
for obj in emp:
obj.printStatement()
print('\n')
print("The total payout for all employees combined is " +
str(totalPayout))
how can i add overtime into this and calculate the number of employees entered?
Python code included overtime and number of employees entered.
class employee: name = str('') hourlyWage = 0 hoursWorked = 0 # added overtime hours and wages overtimeHourlyWage = 0 overtimeHoursWorked = 0 # added payment of overtime def getPayment(self): payment = (self.hourlyWage * self.hoursWorked) + (self.overtimeHourlyWage * self.overtimeHoursWorked) return payment class payrollApp(employee): def printStatement(self): print('The Employee Name is ' + self.name) print('The Employee Hourly wage is ' + str(self.hourlyWage)) print('No of hours worked ' + str(self.hoursWorked)) print('The Employee overtime Hourly wage is ' + str(self.overtimeHourlyWage)) print('No of overtime hours worked ' + str(self.overtimeHoursWorked)) print('The Employee payment is ' + str(employee.getPayment(self))) if __name__ == '__main__': emp = [] x = 0 a = True totalPayout = 0 while a: emp.append(payrollApp()) emp[x].name = input("Enter Employee Name: ") emp[x].hourlyWage = int(input("Enter hourly wage: ")) emp[x].hoursWorked = int(input("Enter No of hours worked: ")) # Taking overtime input emp[x].overtimeHourlyWage = int(input("Enter overtime hourly wage: ")) emp[x].overtimeHoursWorked = int(input("Enter No of overtime hours worked: ")) totalPayout = totalPayout + emp[x].getPayment() print("\n") x = x + 1 b = input("Do you want to enter new employee yes or no ") print('\n') if b == 'no': a = False for obj in emp: obj.printStatement() print('\n') # print total number of employees print("Total number of employees: " + str(x)) print("The total payout for all employees combined is " + str(totalPayout)) Image for indentation :
Output :
Enter Employee Name: abc
Enter hourly wage: 100
Enter No of hours worked: 6
Enter overtime hourly wage: 120
Enter No of overtime hours worked: 2
Do you want to enter new employee yes or no yes
Enter Employee Name: xyz
Enter hourly wage: 120
Enter No of hours worked: 8
Enter overtime hourly wage: 150
Enter No of overtime hours worked: 1
Do you want to enter new employee yes or no no
The Employee Name is abc
The Employee Hourly wage is 100
No of hours worked 6
The Employee overtime Hourly wage is 120
No of overtime hours worked 2
The Employee payment is 840
The Employee Name is xyz
The Employee Hourly wage is 120
No of hours worked 8
The Employee overtime Hourly wage is 150
No of overtime hours worked 1
The Employee payment is 1110
Total number of employees: 2
The total payout for all employees combined is 1950
Hope you like it
Any Query? Comment Down!
I have written for you, Please up vote the answer as it encourage us to serve you Best !