A lot of starter code just need to implement 2 methods all instructions and sample tests...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
A lot of starter code just need to implement 2 methods all instructions and sample tests are provided (Should not take long) (USING PYTHON 3.9) 1) Implement Employee.total_pay. Read the header and docstring for the new method. Decide if it should be implemented in the base class, or made abstract and implemented in the subclasses. (Even though the doctest for this method is in the base class, we can still make it an abstract method.) You may add new instance attribute(s) to implement the required functionality; just make sure to document them in the class docstring, add type annotations for them, and initialize them properly. You may assume as a precondition that the pay method is not called on the same employee twice in the same month. (Remember: "precondition" means here that your implementation can assume that it's true, and does not need to check for it.) 2) Implement Company.total_payroll. Read the header docstring for this method carefully. To implement this method, you should not need to add any additional attributes in the Company class. (DO NOT MAKE CHANGES TO OTHER METHODS + DO NOT IMPORT ANYTHING) (Methods that need to be implemented have #TODO) Sample Tests: def test_total_pay_basic() -> None: e = SalariedEmployee (14, 'Gilbert the cat', 1200.0) e.pay(date (2018, 6, 28)) e.pay(date(2018, 7, 28)) e.pay(date (2018, 8, 28)) assert e.total_pay() == 300.0 def test total_payroll_mixed () -> None: my_corp = Company ( [Salaried Employee (24, Gilbert the cat', 1200.0), Hourly Employee (25, 'Chairman Meow', 500.25, 1)]) (2018, 6, 28)) my_corp.pay_all(date assert my_corp.total_payroll() == 600.25 For the given code implement the methods Employee.total_pay and Company.total_payroll : === Module Description === This module contains an illustration of *inheritance* through an abstract Employee class that defines a common interface for all of its subclasses. from datetime import date 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. 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. MILIT raise NotImplemented Error def pay(self, pay_date: date) -> None: """Pay this Employee on the given date and record the payment. (Assume this is called once per month.) HIGH 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 = Salaried Employee (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 MILI #TODO: implement this method! pass class Salaried Employee (Employee): """An employee whose pay is computed based on an annual salary. ===Public attributes === salary: This employee's annual salary === Representation invariants === salary >= 0 - id: int name: str salary: float definit_(self, id int, name: str, salary: float) -> None: """Initialize this salaried Employee. >>> e = salaried Employee (14, 'Fred Flintstone', 5200.0) >>> e.salary 5200.0 # Note that to call the superclass' initializer, we need to use the # full name '_init_'. This is the only time we write '__init__* # explicitly. 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 = Salaried Employee (99, 'Mr slate', 120000.0) >>> e.get_monthly_payment() 10000.0 It return round(self.salary 12, 2) 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 === - hourly_wage >= 0 hours_per_month >= 0 FEST 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 Hourly Employee. >>> 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 = Hourly Employee (23, Barney Rubble', 1.25, 50.0) >>> e.get_monthly_payment() 62.5 HIU monthly_total = self.hours_per_month *self.hourly_wage return round(monthly_total, 2) class Company: """A company with employees. We use this class mainly as a client for the various Employee classes we defined in employee. === Attributes === employees: the employees in the company. employees: list [Employee] def _init_(self, employees: list[Employee]) -> None: self. employees = employees def pay_all(self, pay_date: date) -> None: """Pay all employees at this company. for employee in self.employees: employee.pay (pay_date) www def total_payroll(self) -> float: ***"Return the total of all payments ever made to all employees. >>> my_corp = Company ([\ SalariedEmployee (24, "Gilbert the cat', 1200.0), \ HourlyEmployee (25, 'Chairman Meow', 500.25, 1.0)]) >>> my_corp.pay_all(date (2022, 6, 28)) An employee was paid 100.0 on 2022-06-28. An employee was paid 500.25 on 2022-06-28. >>> my_corp.total_payroll() 600.25 # TODO: implement this method! pass A lot of starter code just need to implement 2 methods all instructions and sample tests are provided (Should not take long) (USING PYTHON 3.9) 1) Implement Employee.total_pay. Read the header and docstring for the new method. Decide if it should be implemented in the base class, or made abstract and implemented in the subclasses. (Even though the doctest for this method is in the base class, we can still make it an abstract method.) You may add new instance attribute(s) to implement the required functionality; just make sure to document them in the class docstring, add type annotations for them, and initialize them properly. You may assume as a precondition that the pay method is not called on the same employee twice in the same month. (Remember: "precondition" means here that your implementation can assume that it's true, and does not need to check for it.) 2) Implement Company.total_payroll. Read the header docstring for this method carefully. To implement this method, you should not need to add any additional attributes in the Company class. (DO NOT MAKE CHANGES TO OTHER METHODS + DO NOT IMPORT ANYTHING) (Methods that need to be implemented have #TODO) Sample Tests: def test_total_pay_basic() -> None: e = SalariedEmployee (14, 'Gilbert the cat', 1200.0) e.pay(date (2018, 6, 28)) e.pay(date(2018, 7, 28)) e.pay(date (2018, 8, 28)) assert e.total_pay() == 300.0 def test total_payroll_mixed () -> None: my_corp = Company ( [Salaried Employee (24, Gilbert the cat', 1200.0), Hourly Employee (25, 'Chairman Meow', 500.25, 1)]) (2018, 6, 28)) my_corp.pay_all(date assert my_corp.total_payroll() == 600.25 For the given code implement the methods Employee.total_pay and Company.total_payroll : === Module Description === This module contains an illustration of *inheritance* through an abstract Employee class that defines a common interface for all of its subclasses. from datetime import date 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. 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. MILIT raise NotImplemented Error def pay(self, pay_date: date) -> None: """Pay this Employee on the given date and record the payment. (Assume this is called once per month.) HIGH 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 = Salaried Employee (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 MILI #TODO: implement this method! pass class Salaried Employee (Employee): """An employee whose pay is computed based on an annual salary. ===Public attributes === salary: This employee's annual salary === Representation invariants === salary >= 0 - id: int name: str salary: float definit_(self, id int, name: str, salary: float) -> None: """Initialize this salaried Employee. >>> e = salaried Employee (14, 'Fred Flintstone', 5200.0) >>> e.salary 5200.0 # Note that to call the superclass' initializer, we need to use the # full name '_init_'. This is the only time we write '__init__* # explicitly. 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 = Salaried Employee (99, 'Mr slate', 120000.0) >>> e.get_monthly_payment() 10000.0 It return round(self.salary 12, 2) 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 === - hourly_wage >= 0 hours_per_month >= 0 FEST 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 Hourly Employee. >>> 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 = Hourly Employee (23, Barney Rubble', 1.25, 50.0) >>> e.get_monthly_payment() 62.5 HIU monthly_total = self.hours_per_month *self.hourly_wage return round(monthly_total, 2) class Company: """A company with employees. We use this class mainly as a client for the various Employee classes we defined in employee. === Attributes === employees: the employees in the company. employees: list [Employee] def _init_(self, employees: list[Employee]) -> None: self. employees = employees def pay_all(self, pay_date: date) -> None: """Pay all employees at this company. for employee in self.employees: employee.pay (pay_date) www def total_payroll(self) -> float: ***"Return the total of all payments ever made to all employees. >>> my_corp = Company ([\ SalariedEmployee (24, "Gilbert the cat', 1200.0), \ HourlyEmployee (25, 'Chairman Meow', 500.25, 1.0)]) >>> my_corp.pay_all(date (2022, 6, 28)) An employee was paid 100.0 on 2022-06-28. An employee was paid 500.25 on 2022-06-28. >>> my_corp.total_payroll() 600.25 # TODO: implement this method! pass
Expert Answer:
Answer rating: 100% (QA)
Answer The required code is as follow from typing import List from datetime import date class Employ... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
Understanding that it is not a weakness but a strength to be a vulnerable and humble leader, identify three ethics you feel are areas of strength and three that are areas you will need to work a...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
The Crazy Eddie fraud may appear smaller and gentler than the massive billion-dollar frauds exposed in recent times, such as Bernie Madoffs Ponzi scheme, frauds in the subprime mortgage market, the...
-
What is data science, how does it differ from traditional statistics, explain data science process, including the key steps involve in it.
-
Light with wavelength 648nm in air is incident perpendicularly from air on a film 8.76m thick and with refractive index 1.35. Part of the light is reflected from the first surface of the film, and...
-
Locate the centroid x of the shaded area. y 4 m y = 4 - 16 -8 m-
-
A new graduate hired by the marketing research department of AT\&T is asked to prepare a questionnaire to determine household preferences for cell phone plans. The questionnaire is to be administered...
-
Levine Manufacturing pays its production managers a bonus based on the company's profitability. During the two most recent years, the company maintained the same cost structure to manufacture its...
-
Brite Toothbrushes has gathered the following Information to complete its Production Report for the month of April. Assume all materials are added at the beginning of the process. Required: Using the...
-
You send daily emails about a variety of topics for a shoe store. Your open rates are low, but sale announcements perform best. Which two marketing actions would most likely increase open rates?...
-
Based on historical data, the Hospital of St. Jacques wants to have 7 bags of B positive blood to every 2 bags of B Negative, furthermore, they want to have 3 bags of B negative blood for every 1 bag...
-
The condensed income statement for the Consumer Products Division of Fargo Industries Inc. is as follows (assuming no service department charges): Sales Cost of goods sold Gross profit $894,000...
-
Baillie Power leased high-tech electronic equipment from Courtney Leasing on January 1, 2024. Courtney purchased the equipment from Doane Machines at a cost of $252,000, its fair value. Note: Use...
-
BatCo makes baseball bats. Each bat requires 2.00 pounds of wood at $16 per pound and 0.25 direct labor hour at $20 per hour. Overhead is assigned at the rate of $40 per direct labor hour. Assume the...
-
A manufactured product has the following Information for June. Direct materials Direct labor Overhead Units manufactured Standard Quantity and Cost 6 pounds @ $8 per pound 3 DLH @ $17 per DLH 3 DLH @...
-
How can a financial risk can be managed? What is financial risk? what does it include and exclude? What do we study in the financial risk manager?
-
Consider the following reaction: 2 NO(g) 2 N(g) + O(g) part A: Express the rate of the reaction in terms of the change in concentration of each of the reactants and products. Part B: In the first...
-
Time Solutions, Inc. is an employment services firm that places both temporary and permanent workers with a variety of clients. Temporary placements account for 70% of Time Solutions' revenue;...
-
Charlie's Green Lawn Care is a cash basis taxpayer. Charlie Adame, the sole proprietor, is considering delaying some of his December 2012 customer billings for lawn care into the next year. In...
-
During 2012, Palo Fiero purchases the following property for use in his manufacturing business: Palo uses the accelerated depreciation method under MACRS, if available, and does not make the election...
-
In June of 2012, Maureen's house is vandalized during a long-term power failure after a hurricane hit the city. The president of the United States declares Maureen's city a disaster area as a result...
-
Example In January 2004, a Mars Exploration Rover touched down on the surface of Mars and rolled out for exploration ( Figure
-
Does the snowflake have rotational symmetry in Figure 1.6? If yes, describe the ways in which the flake can be rotated without changing its appearance. Does it have reflection symmetry? If yes,...
-
A battery-operated wall clock no longer keeps timeneither hand moves. Develop a hypothesis explaining why it fails to work, and then make a prediction that permits you to test your hypothesis....
Study smarter with the SolutionInn App