Write this assignment using data classes
1 Create a class Person a. Initialize a class Person 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
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.
class Person:
def __init__(self,firstName,lastName,age,address,contactNumber):
self._FirstName=firstName
self._LastName=lastName
self._Age=age
self._Address=address
self._ContactNumber =contactNumber
class Employee(Person):
def __init__(self, firstName,lastName,age,address,contactNumber,employeeID,organizationName,position):
self._EmployeeID=employeeID
self._OrganizationName=organizationName
self._Position=position
super().__init__(firstName,lastName,age,address,contactNumber)
class CommissionEmployee(Employee):
def __init__(self, firstName,lastName,age,address,contactNumber,employeeID,organizationName,position,commissionRate):
self.__CommissionRate=commissionRate
super().__init__(firstName,lastName,age,address,contactNumber,employeeID,organizationName,position)
def calculateCommission(self,grossSale):
return grossSale*self.__CommissionRate
def displayData(self):
print(f"First Name: {self._FirstName}")
print(f"Last Name: {self._LastName}")
print(f"Age: {self._Age}")
print(f"Address: {self._Address}")
print(f"Contact Number: {self._ContactNumber}")
print(f"Employee ID: {self._EmployeeID}")
print(f"Organization Name: {self._OrganizationName}")
print(f"Position: {self._Position}")
print(f"Commission Rate: {self.__CommissionRate}")
def main():
ce=CommissionEmployee("Peter","Smith",55,"WC 4554","48965-456","4551320","Space X","Programmer",0.05)
grossSale=float(input("Enter gross sale: "))
commission=ce.calculateCommission(grossSale)
grossSale=grossSale-commission
ce.displayData()
print(f"Total earning: {grossSale}")
main()
Comments
Leave a comment