PYTHON Add a method calculate_pay() to the Employee class. The method should ret
ID: 3769605 • Letter: P
Question
PYTHON
Add a method calculate_pay() to the Employee class. The method should return the amount to pay the employee by multiplying the employee's wage and number of hours worked.
Edit the following code:
class Employee:
def __init__(self):
self.wage = 0
self.hours_worked = 0
# def ... Add new method here ...
# ...
alice = Employee()
alice.wage = 9.25
alice.hours_worked = 35
print('Alice: Net pay: %f' % alice.calculate_pay())
bob = Employee()
bob.wage = 11.50
bob.hours_worked = 20
print('Bob: Net pay: %f' % bob.calculate_pay())
Explanation / Answer
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace PayScale { class EmpPayScale { private const decimal FED_TAX = .18M; private const decimal RETIRE_CONTRIB = .10M; private const decimal SOC_SEC = .06M; private decimal payScaleHourly; private decimal payScaleSalary; private decimal grossIncome; private decimal rate; private decimal hours; public EmpPayScale() { } public EmpPayScale(decimal hrs, decimal payRate, decimal grossInc) { hours = hrs; rate = payRate; grossIncome = grossInc; } public decimal PayScaleHourly { get { return payScaleHourly; } } public decimal PayScaleSalary { get { return payScaleSalary; } } public void SetPayScale(string payClassIf) { if (payClassIf == "PT") { if (hours < 40) payScaleHourly = (rate * hours); } else if (payClassIf == "OT") { if (hours > 40) payScaleHourly = (rate * hours) * 1.5M; } else if (payClassIf == "Salary") { payScaleSalary = grossIncome - (grossIncome * (FED_TAX + RETIRE_CONTRIB + SOC_SEC)); } else { Console.WriteLine("Enter correct Employee Pay Schedule: " + " PT" + " OT" + " Salary"); } } } }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.