Answer to Question #292598 in Python for dv13

Question #292598

1. Create a class Person

a. Initialize a class Person (Constructor method) with FirstName, LastName, Age, Address and Contact Number.


2. Create a class Employee

a. employee is a Person so Employee is a child class of Person class. Employee class 

constructor/__init__ method will contain all the attributes of Person class and Employee 

class own attributes which are EmployeeID, OrganizationName and Position  


3. Create a class CommissionEmployee  15 Marks 

a. CommissionEmployee is a child class of Employee class. It should inherit all the attributes of Employee class and its own attribute which is commissionRate 


b. Create a method called calculateCommission, which should take input of gross sale from the user and based on the commission rate calculate the totalEarning. 


c. Create a method called displayData which should display the FirstName, LastName, Age, Address, ContactNumber, EmployeeID, OrganizationName, Position, commissionRate and  totalEarning.  


1
Expert's answer
2022-02-01T06:22:57-0500
import datetime #datetime lib is used
class Person:

    def __init__(self, name, surname, birthdate, address, telephone, email):
        self.name = name
        self.surname = surname
        self.birthdate = birthdate

        self.address = address
        self.telephone = telephone
        self.email = email

        self._age = None
        self._age_last_recalculated = None

        self._recalculate_age()

    def _recalculate_age(self):
        today = datetime.date.today()
        age = today.year - self.birthdate.year

        if today < datetime.date(today.year, self.birthdate.month, self.birthdate.day):
            age -= 1

        self._age = age
        self._age_last_recalculated = today

    def age(self):
        if (datetime.date.today() > self._age_last_recalculated):
            self._recalculate_age()

        return self._age

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS