Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

An employee of a company. This is an abstract class. Only child classes should be instantiated. Public Attributes: - id _ :

"""An employee of a company.
This is an abstract class. Only child classes should be instantiated.
Public Attributes:
- id_: This employee's ID number.
- name: This employee's name.
Private Attributes: (add yours here)
-
"""
id_: int
name: str
def __init__(self, id_: int, name: str)-> None:
"""Initialize this employee.
Note: This initializer is meant for internal use only;
Employee is an abstract class and should not be instantiated directly.
"""
self.id_= id_
self.name = name
def get_monthly_payment(self)-> float:
"""Return the amount that this Employee should be paid in one month.
Round the amount to the nearest cent.
"""
raise NotImplementedError
def pay(self, pay_date: date)-> None:
"""Pay this Employee on the given date and record the payment.
(Assume this is called at most once per month.)
"""
payment = self.get_monthly_payment()
print(f'An employee was paid {payment} on {pay_date}.')
def total_pay(self)-> float:
"""Return the total amount of pay` this Employee has received.
>>> e = SalariedEmployee(14, 'Gilbert the cat', 1200.0)
>>> e.pay(date(2018,6,28))
An employee was paid 100.0 on 2018-06-28.
>>> e.pay(date(2018,7,28))
An employee was paid 100.0 on 2018-07-28.
>>> e.pay(date(2018,8,28))
An employee was paid 100.0 on 2018-08-28.
>>> e.total_pay()
300.0
"""
# TODO: implement this method! (You'll need to add at least one
# instance attribute to this class to complete this method.)
@check_contracts
class SalariedEmployee(Employee):
"""An employee whose pay is computed based on an annual salary.
Public Attributes:
- salary: This employee's annual salary
Representation Invariants:
- self.salary >=0
"""
id_: int
name: str
salary: float
def __init__(self, id_: int, name: str, salary: float)-> None:
"""Initialize this salaried Employee.
Preconditions:
- salary >=0
>>> e = SalariedEmployee(14, 'Fred Flintstone', 5200.0)
>>> e.salary
5200.0
"""
Employee.__init__(self, id_, name)
self.salary = salary
def get_monthly_payment(self)-> float:
"""Return the amount that this Employee should be paid in one month.
Round the amount to the nearest cent.
>>> e = SalariedEmployee(99,'Mr Slate', 120000.0)
>>> e.get_monthly_payment()
10000.0
"""
return round(self.salary /12,2)
@check_contracts
class HourlyEmployee(Employee):
"""An employee whose pay is computed based on an hourly rate.
Public Attributes:
- hourly_wage:
This employee's hourly rate of pay.
- hours_per_month:
The number of hours this employee works each month.
Representation Invariants:
- self.hourly_wage >=0
- self.hours_per_month >=0
"""
id_: int
name: str
hourly_wage: float
hours_per_month: float
def __init__(self, id_: int, name: str, hourly_wage: float,
hours_per_month: float)-> None:
"""Initialize this HourlyEmployee.
Preconditions:
- hourly_wage >=0
- hours_per_month >=0
>>> barney = HourlyEmployee(23, 'Barney Rubble', 1.25,50.0)
>>> barney.hourly_wage
1.25
>>> barney.hours_per_month
50.0
"""
Employee.__init__(self, id_, name)
self.hourly_wage = hourly_wage
self.hours_per_month = hours_per_month
def get_monthly_payment(self)-> float:
"""Return the amount that this Employee should be paid in one month.
Round the amount to the nearest cent.
>>> e = HourlyEmployee(23, 'Barney Rubble', 1.25,50.0)
>>> e.get_monthly_payment()
62.5
"""
return round(self.hours_per_month * self.hourly_wage, 2)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Murach's SQL Server 2012 For Developers

Authors: Bryan Syverson, Joel Murach, Mike Murach

1st Edition

1890774693, 9781890774691

More Books

Students also viewed these Databases questions

Question

Excel caculation on cascade mental health clinic

Answered: 1 week ago

Question

=+d. Is there another print vehicle you would suggest?

Answered: 1 week ago