from decimal import Decimal class CommissionEmployee: """ An employee who gets paid a commission based on gross sales. """ def __init__(self, first_name, last_name, ssn, gross_sales, commission_rate): """ Construct a CommissionEmployee object. @param first_name the employee's first name. @param last_name the employee's last name. @param ssn the employee's SSN. @param gross_sales the employee's gross sales.. @param commission_rate the employee's commission rate. """ 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 the gross sales or raise ValueError if invalid. @param sales the gross sales. """ 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. @param rate the commission rate. """ 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): """ @return the employee's earnings. """ return self.gross_sales * self.commission_rate def __repr__(self): """ @return the string representation of an CommissionEmployee object. """ return ('CommissionEmployee: ' + f'{self.first_name} {self.last_name}\n' + f'social security number: {self.ssn}\n' + f'gross sales: ${self.gross_sales:,.2f}\n' + f'commission rate: {self.commission_rate:.2f}') ########################################################################## # (C) Copyright 2019 by Deitel & Associates, Inc. and # # Pearson Education, Inc. All Rights Reserved. # # # # DISCLAIMER: The authors and publisher of this book have used their # # best efforts in preparing the book. These efforts include the # # development, research, and testing of the theories and programs # # to determine their effectiveness. The authors and publisher make # # no warranty of any kind, expressed or implied, with regard to these # # programs or to the documentation contained in these books. The authors # # and publisher shall not be liable in any event for incidental or # # consequential damages in connection with, or arising out of, the # # furnishing, performance, or use of these programs. # ########################################################################## # Additional material (C) Copyright 2024 by Ronald Mak