info_outline

Solutions will be available when this assignment is resolved, or after a few failing attempts.

Payroll

Create a class Employee with two subclasses: SalariedEmployee and HourlyEmployee.

Employee receives a name parameter and has a __str__ method (prints like "[name] makes [annual_income] annually").

SalariedEmployee should receive parameters for name and salary. It has a method calculate_annual_income that returns the salary for that person.

HourlyEmployee should receive parameters for name and hourly_wage. It has a method calculate_annual_income that returns the annual income, calculated by multiplying the hourly_wage * 40 (hrs per week) * 52 (weeks).

The Payroll class receives a parameter for company and an optional argument for employee_list. If there is no employee_list, set it to an empty list. It has two methods:
- add_employee receives an employee as a parameter and adds it to the employee_list
- get_annual_payroll_cost adds up the total annual income for each employee in the employee_list and returns it

Example:

emp1 = SalariedEmployee("Bill", 60000)
emp2 = HourlyEmployee("Ted", 25)

emp1.name # "Bill"
emp1.calculate_annual_income() # 60000
print(emp1) # "Bill makes 60000 annually"

emp1.calculate_annual_income() # 60000
emp2.calculate_annual_income() # 52000

payroll = Payroll("Excellent Adventures")
payroll.company # "Excellent Adventures"

payroll.add_employee(emp1)
payroll.add_employee(emp2)
payroll.get_annual_payroll_cost() # 112000

Test Cases

test salaried - Run Test

def test_salaried():
    emp1 = SalariedEmployee("Bill", 60000)

    assert emp1.name == "Bill"
    assert emp1.salary == 60000

    assert emp1.calculate_annual_income() == 60000
    assert str(emp1) == "Bill makes 60000 annually"

test payroll - Run Test

def test_payroll():
    emp1 = SalariedEmployee("Bill", 60000)
    emp2 = HourlyEmployee("Ted", 25)
    
    payroll = Payroll("Excellent Adventures")
    assert payroll.company == "Excellent Adventures"

    payroll.add_employee(emp1)
    payroll.add_employee(emp2)
    assert payroll.get_annual_payroll_cost() == 112000

test hourly - Run Test

def test_hourly():
    emp1 = HourlyEmployee("Ted", 25)

    assert emp1.name == "Ted"
    assert emp1.hourly_wage == 25

    assert emp1.calculate_annual_income() == 52000
    assert str(emp1) == "Ted makes 52000 annually"
    
class Payroll(object): pass class Employee(object): pass