Stacks 3

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

class Employee: #Base class Employee

def __init__(self, name, employee_id):


self._name = name
self._employee_id = employee_id

@property
def name(self): #getter for name
return self._name

@name.setter
def name(self, name): #Setter for name
self._name = name

@property
def employee_id(self): #getter for Employee Id
return self._employee_id

@employee_id.setter
def name(self, employee_id): #Setter for Employee ID
self._employee_id = employee_id

def calculate_payment(self): #Method to calculate payment, An abstract


pass

def display_result(self): #Method to display Information


return f"\nEmployee's Name: {self.name} \nEmployee ID: {self.employee_id}"

class HourlyWorker(Employee): #Subclass


def __init__(self, name, employee_id, hourly_rate, hours_worked):
super().__init__(name, employee_id)
self._hourly_rate = hourly_rate
self._hours_worked = hours_worked

def calculate_payment(self): #Method


return self._hourly_rate * self._hours_worked

def display_result(self): #Method


return f"{Employee.display_result(self)} \nPayment:
{self.calculate_payment()}"

class PieceWorker(Employee): #Subclass


def __init__(self, name, employee_id, pieces_completed, rate_per_piece):
super().__init__(name, employee_id)
self._pieces_completed = pieces_completed
self._rate_per_piece = rate_per_piece

def calculate_payment(self):
if self._pieces_completed > 200:
return self._pieces_completed * self._rate_per_piece + 100
else:
return self._pieces_completed * self._rate_per_piece

def display_result(self):
return f"{Employee.display_result(self)} \nPayment:
{self.calculate_payment()}"

class SalesEmployee:
def __init__(self, sales_amount, commission_rate):
self._sales_amount = sales_amount
self._commission_rate = commission_rate

def calculate_payment(self):
return self._hourly_rate * self._hours_worked

def display_result(self):
return f"{Employee.display_result(self)} \nPayment:
{self.calculate_payment()}"

class CommissionWorker(Employee, SalesEmployee):


def __init__(self, name, employee_id, sales_amount, commission_rate,
base_salary):
Employee.__init__(name, employee_id)
SalesEmployee.__init__(sales_amount, commission_rate)
self._base_salary = base_salary

def calculate_payment(self):
return (self._sales_amount * (self._commission_rate / 100)) +
self._base_salary

def display_result(self):
return f"{Employee.display_result(self)} \nPayment:
{self.calculate_payment()}"

employee_list = [
Employee("rods", 1234),
HourlyWorker("jap", 1234, 20, 12),
PieceWorker("Eunice", 1332, 20, 10),
# CommissionWorker("James", 14552, 21, 100, 50)
]

for employee in employee_list:


print(employee.display_result())

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy