write this python code using data Classes
4. Create a class SalariedEmployee
a. SalariedEmployee class is a child class of Employee class. It should inherit all the attributes of
Employee class and add its own attribute baseSalary.
b. Create a method called CalculateNetSalary which should deduct 13% Provisional Tax, 1%
insurance and 3% Fed Tax from baseSalary and display the NetSalary.
c. Create a method called displayData which should display the FirstName, LastName, Age,
Address, ContactNumber, EmployeeID, OrganizationName, Position, baseSalary and
NetSalary.
5. Create a class BasePlusCommissionEmployee
a. BasePlusCommissionEmployee class is a child class of CommissionEmployee. It should inherit
all the attributes of CommissionEmployee class and add its own attribute baseSalary.
b. Create a method called calculateTotalEarning which should inherit super class method
calculateCommission and add baseSalary in it.
from email.mime import base
class Employee:
def __init__(self, fName, lName, age, address, cntNumber, id,
orgName, pos):
self.firstName = fName
self.lastName = lName
self.age = age
self.address = address
self.contactNumbe = cntNumber
self.ID = id
self.organizationName = orgName
self.position = pos
class SalaryEmployee(Employee):
def __init__(self, fName, lName, age, address, cntNumber, id,
orgName, pos, baseSalary):
super.__init__(fName, lName, age, address, cntNumber, id,
orgName, pos)
self.baseSalary = baseSalary
def CalculateNetSalary(self):
provTax = 0.13 * self.baseSalary
insurance = 0.01 * self.baseSalary
fedTax = 0.03 * self.baseSalary
netSalary = self.baseSalary - provTax - insurance - fedTax
return netSalary
def DisplayData(self):
print('First name:', self.firstName)
print('Last name:', self.lastName)
print('Age:', self.age)
print('Address:', self.address)
print('Contact number:', self.contactNumbe)
print('Employee ID:', self.ID)
print('Organization name:', self.organizationName)
print('Position:', self.position)
netSalary = self.CalculateNetSalary()
print(f'Net salary: ${netSalary:.2f}')
class CommissionEmployee(Employee):
def __init__(self, fName, lName, age, address, cntNumber, id,
orgName, pos, commision):
super.__init__(fName, lName, age, address, cntNumber, id,
orgName, pos)
self.commision = commision
def CalculateCommision(self, income):
return income * self.commision
class BasePlusCommissionEmployee(CommissionEmployee):
def __init__(self, fName, lName, age, address, cntNumber, id,
orgName, pos, commision, base):
super.__init__(fName, lName, age, address, cntNumber, id,
orgName, pos, commision)
self.baseSalary = base
def CalculateTotalEarning(self, income):
return self.CalculateCommision(income) + self.baseSalary
Comments
Leave a comment