Question
Pyathon-3 A complete class for CommissionEmployee is given below. CommissionEmployee is being paid a percentage of sales. You need to do: 1. Write a Python
Pyathon-3
A complete class for CommissionEmployee is given below.
CommissionEmployee is being paid a percentage of sales.
You need to do:
1.Write a Python program for SalariedCommissionEmployee class using the CommissionEmployee as the base class.
A SalariedCommissionEmployee will receive a percentage of their sales and base salary.
The new attribute for the derived class is: base_salary
The earnings method would include: commission + base_salary
Override the def__repr__(self) for this new class to include base_salary
2. Write a main program to demonstrate that it has all the capabilities of the base class and subclass with appropriate printouts
3. Draw a Class Diagram showing attributes and methods & inheritance relationship between CommissionEmployee and SalariedCommissionEmployee
-------------------------------Complete the program------------------------------------------
# commmissionemployee.py
"""CommissionEmployee base class."""
from decimal import Decimal
class CommissionEmployee:
"""An employee who gets paid commission based on gross sales."""
def __init__(self, first_name, last_name, ssn,
gross_sales, commission_rate):
"""Initialize CommissionEmployee's attributes."""
self._first_name = first_name
self._last_name = last_name
self._ssn = ssn
self.gross_sales = gross_sales # validate via property
self.commission_rate = commission_rate # validate via property
@property
def first_name(self):
return self._first_name
@property
def last_name(self):
return self._last_name
@property
def ssn(self):
return self._ssn
@property
def gross_sales(self):
return self._gross_sales
@gross_sales.setter
def gross_sales(self, sales):
"""Set gross sales or raise ValueError if invalid."""
if sales < Decimal('0.00'):
raise ValueError('Gross sales must be >= to 0')
self._gross_sales = sales
@property
def commission_rate(self):
return self._commission_rate
@commission_rate.setter
def commission_rate(self, rate):
"""Set commission rate or raise ValueError if invalid."""
if not (Decimal('0.0') < rate < Decimal('1.0')):
raise ValueError(
'Interest rate must be greater than 0 and less than 1')
self._commission_rate = rate
def earnings(self):
"""Calculate earnings."""
return self.gross_sales * self.commission_rate
def __repr__(self):
"""Return string representation for repr()."""
return ('CommissionEmployee: ' +
f'{self.first_name} {self.last_name} ' +
f'social security number: {self.ssn} ' +
f'gross sales: {self.gross_sales:.2f} ' +
f'commission rate: {self.commission_rate:.2f}')
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started