Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

# Part 1 # In this part of the prep, you will implement the total _ pay method of the # Employee class. # #

# Part 1
# In this part of the prep, you will implement the total_pay method of the
# Employee class.
#
# You may add new PRIVATE instance attributes to the class to help store a
# record of the payments. Private instance attributes are attributes whose
# names start with _ and should not be accessed by code outside of the class.
#
# Document any new attributes in your class docstring, include type annotations
# for them in the class body, and make sure you initialize them properly
# in the Employee.__init__ method. You can, and should, also update the
# Employee.pay method implementation to update your new attribute(s).
#
# You may assume as a precondition that the pay method is not called on the
# same employee twice in the same month.
#
# NOTE: You only need to change the Employee class, and you should NOT change
# its two subclasses (they will simply inherit the Employee.total_pay method).
################################################################################
@check_contracts
class Employee:
"""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 record_payment(self)-> float:
""" Record each payment of a employee.
>>> cable = SalariedEmployee(1234, 'cable', 1200.0)
>>> cable.pay(date(2023,1,28))
An employee was paid 100.0 on 2023-01-28.
>>> cable.pay(date(2023,2,28))
An employee was paid 100.0 on 2023-02-28.
>>> cable.record_payment()
300.0
"""
result =0
if self.pay():
result +=1
return result
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.)
return (self.get_monthly_payment * self.record_payment)

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

Students also viewed these Databases questions

Question

Explain the impact of organizational culture on employees.

Answered: 1 week ago