You are on page 1of 16

Machine Problem 4 - Classes/Objects

Create a class EmployeePayroll that has the following attributes and methods (see Table 1). You
will use this class

to calculate the employee’s monthly gross income and other necessary details.

The monthly gross income is computed by deducting the total contributions

from the monthly basic salary. The total contributions include the sum of GSIS,

PHILHEALTH, PAG-IBIG and the withholding tax (wtax). GSIS is 9% of the

monthly basic salary. PHILHEALTH, PAG-IBIG and withholding tax are computed
based on the tables 2, 3, and 4 below.

Compute the age based on the employee’s birthday given in this format

“mm/dd/yyyy”. The method promote updates the position and the basic salary of the employee

by including two parameters: the new position and the new basic salary of the

employee.

Create a driver program to test the functionalities of the class methods.

(See sample data on the next page.)

Table 1: Attributes & Methods of

the Employee Payroll class

EmployeePayroll

attribute

first name: str

last name: str

birthday: str

gender: str

civil status: str


position: str

basic salary: float

method

get_age()

get_gsis_contrib()

get_philhealth_contrib()

get_pagibig_contrib()

get_wtax()

get_total_deductions()
get_gross_income()

promote()

Table 2: PhilHealth Contribution Table for Employees

Monthly Basic Salary Employee Share


P10,000 and below P200
P10,000.01 to P79,999.99 2%
P80,000 and above P1,600

Table 3: Pag-IBIG Contribution Table for Employees

Monthly Salary Employee’s Contribution Rate


At least P1,000 to P1,500 1%
Over P1,500 2%

Table 4: Withholding Tax Table for Employees

Monthly Basic Salary Withholding Tax


1 20,833 and below 0.00
2 20,833 - 33,332 0.00 + 15% over 20,833
3 33,333 - 66,666 1,875.00 + 20% over 33,333
4 66,667 – 166,666 8,541.80 + 25% over 66,667
5 166,667 – 666,666 33,541.80 + 30% over 166.667
6 666,667 and above 183,541.80 + 35% over 666,667
Table 5: Sample Employee Data

First Last Birthday Gender Civil Position Monthly


name name Status Basic
Salary
(PhP)

Employe Thomas Cooper 05/10/19 M Married Compute 347,983.


e1 79 r 33
Engineer
Employe Kirk Curry 07/01/19 M Married Compute
e2 85 r 165,241.
Network 67
Architect
Employe Jesse Mitchell 03/01/19 F Married Software
e3 80 Develope 154,808.
r 33

Employe Ashley Schmitt 04/06/19 F Single Web


e4 92 developer 77,200.0
0

Employe Raymond Warner 02/19/19 M Single Animator


e5 90 68,108.3
3

Table 6: Sample Payroll

First Last GSIS PHILHE Pag-IBIG WTAX GROSS


name name ALTH INCOME

Employe Thomas Cooper 05/10/19 ? ? ? ?


e1 79
Employe Kirk Curry 07/01/19 ? ? ? ?
e2 85
Employe Jesse Mitchell 03/01/19 ? ? ? ?
e3 80
Employe Ashley Schmitt 04/06/19 ? ? ? ?
e4 92
Employe Raymond Warner 02/19/19 ? ? ? ?
e5 90

After instantiating the objects (on Table 5), display the payroll table (as shown on Table 6).

Display a menu to the user to choose the action he wants to do, such as, but not limited to, View
Payroll, View Employee details,

Promote Employee, Update name, Update civil status. Have a loop to keep the program running
until the user exits.

import datetime

class EmployeePayroll:
def __init__(self, first_name, last_name, birthday, gender, civil_status, position, basic_salary):

self.first_name = first_name

self.last_name = last_name

self.birthday = datetime.datetime.strptime(birthday, "%m/%d/%Y").date()

self.gender = gender

self.civil_status = civil_status

self.position = position

self.basic_salary = basic_salary

def get_age(self):

today = datetime.date.today()

age = today.year - self.birthday.year - ((today.month, today.day) < (self.birthday.month,


self.birthday.day))

print(f"Age: {age}")

def get_gsis_contrib(self):

gsis_contrib = self.basic_salary * 0.09

print(f"GSIS Contribution: {gsis_contrib:.2f}")

def get_philhealth_contrib(self):

if self.basic_salary <= 10000:

philhealth_contrib = 200

elif 10000 < self.basic_salary <= 79999.99:

philhealth_contrib = self.basic_salary * 0.02

else:

philhealth_contrib = 1600

print(f"PhilHealth Contribution: {philhealth_contrib:.2f}")


def get_pagibig_contrib(self):

if 1000 <= self.basic_salary <= 1500:

pagibig_contrib = self.basic_salary * 0.01

else:

pagibig_contrib = self.basic_salary * 0.02

print(f"PAG-IBIG Contribution: {pagibig_contrib:.2f}")

def get_wtax(self):
if self.basic_salary <= 20833:

wtax = 0

elif 20833 < self.basic_salary <= 33332:

wtax = (self.basic_salary - 20833) * 0.15

elif 33333 < self.basic_salary <= 66666:

wtax = 1875 + (self.basic_salary - 33333) * 0.20

elif 66667 < self.basic_salary <= 166666:

wtax = 8541.80 + (self.basic_salary - 66667) * 0.25

elif 166667 < self.basic_salary <= 666666:

wtax = 33541.80 + (self.basic_salary - 166667) * 0.30

else:

wtax = 183541.80 + (self.basic_salary - 666667) * 0.35

print(f"Withholding Tax: {wtax:.2f}")

def get_total_deductions(self):

total_deductions = self.get_gsis_contrib() + self.get_philhealth_contrib() +


self.get_pagibig_contrib() + self.get_wtax()

print(f"Total Deductions: {total_deductions:.2f}")


def get_gross_income(self):

gross_income = self.basic_salary - self.get_total_deductions()

print(f"Gross Income: {gross_income:.2f}")

def promote(self, new_position, new_basic_salary):

self.position = new_position

self.basic_salary = new_basic_salary

print("Employee promoted successfully.")

# Sample Employee Data

employees = [

EmployeePayroll("Thomas", "Cooper", "05/10/1979", "M", "Married", "Computer Engineer",


347983.33),

EmployeePayroll("Kirk", "Curry", "07/01/1985", "M", "Married", "Computer Network


Architect", 165241.67),

EmployeePayroll("Jesse", "Mitchell", "03/01/1980", "F", "Married", "Software Developer",


154808.33),

EmployeePayroll("Ashley", "Schmitt", "04/06/1992", "F", "Single", "Web developer",


77200.00),

EmployeePayroll("Raymond", "Warner", "02/19/1990", "M", "Single", "Animator", 68108.33)

def display_payroll():

print("First Name\tLast Name\tGSIS\tPHILHEALTH\tPag-IBIG\tWTAX\tGROSS


INCOME")

for emp in employees:

print(emp.first_name, emp.last_name, end="\t")

emp.get_gsis_contrib()
emp.get_philhealth_contrib()

emp.get_pagibig_contrib()

emp.get_wtax()

emp.get_gross_income()

def display_employee_details():

for emp in employees:

print(f"Name: {emp.first_name} {emp.last_name}\nGender: {emp.gender}\nBirthday:


{emp.birthday.strftime('%m/%d/%Y')}\nCivil Status: {emp.civil_status}\nPosition:
{emp.position}\nBasic Salary: {emp.basic_salary:.2f}")

emp.get_age()

def promote_employee():

first_name = input("Enter employee's first name: ")

last_name = input("Enter employee's last name: ")

for emp in employees:

if emp.first_name == first_name and emp.last_name == last_name:

new_position = input("Enter new position: ")

new_basic_salary = float(input("Enter new basic salary: "))

emp.promote(new_position, new_basic_salary)

return

print("Employee not found.")

def update_name():

first_name = input("Enter employee's first name: ")

last_name = input("Enter employee's last name: ")

for emp in employees:

if emp.first_name == first_name and emp.last_name == last_name:


new_first_name = input("Enter new first name: ")

new_last_name = input("Enter new last name: ")

emp.first_name = new_first_name

emp.last_name = new_last_name

print("Name updated successfully.")

return

print("Employee not found.")

def update_civil_status():
first_name = input("Enter employee's first name: ")

last_name = input("Enter employee's last name: ")

for emp in employees:

if emp.first_name == first_name and emp.last_name == last_name:

new_civil_status = input("Enter new civil status: ")

emp.civil_status = new_civil_status

print("Civil status updated successfully.")

return

print("Employee not found.")

while True:

print("\n1. View Payroll\n2. View Employee Details\n3. Promote Employee\n4. Update


Name\n5. Update Civil Status\n6. Exit")

choice = input("Enter your choice: ")

if choice == "1":

display_payroll()

elif choice == "2":

display_employee_details()
elif choice == "3":

promote_employee()

elif choice == "4":

update_name()

elif choice == "5":

update_civil_status()

elif choice == "6":

print("Exiting...")

break
else:

print("Invalid choice. Please try again.")


import datetime

class EmployeePayroll:

def __init__(self, first_name, last_name, birthday, gender, civil_status, position, basic_salary):

self.first_name = first_name

self.last_name = last_name

self.birthday = datetime.datetime.strptime(birthday, "%m/%d/%Y").date()

self.gender = gender

self.civil_status = civil_status
self.position = position

self.basic_salary = basic_salary

def get_age(self):

today = datetime.date.today()

age = today.year - self.birthday.year - ((today.month, today.day) < (self.birthday.month,


self.birthday.day))

print(f"Age: {age}")

def get_gsis_contrib(self):

gsis_contrib = self.basic_salary * 0.09

return gsis_contrib

def get_philhealth_contrib(self):

if self.basic_salary <= 10000:

philhealth_contrib = 200

elif 10000 < self.basic_salary <= 79999.99:

philhealth_contrib = self.basic_salary * 0.02


else:

philhealth_contrib = 1600

return philhealth_contrib

def get_pagibig_contrib(self):

if 1000 <= self.basic_salary <= 1500:

pagibig_contrib = self.basic_salary * 0.01

else:

pagibig_contrib = self.basic_salary * 0.02


return pagibig_contrib

def get_wtax(self):

if self.basic_salary <= 20833:

wtax = 0

elif 20833 < self.basic_salary <= 33332:

wtax = (self.basic_salary - 20833) * 0.15

elif 33333 < self.basic_salary <= 66666:

wtax = 1875 + (self.basic_salary - 33333) * 0.20

elif 66667 < self.basic_salary <= 166666:

wtax = 8541.80 + (self.basic_salary - 66667) * 0.25

elif 166667 < self.basic_salary <= 666666:

wtax = 33541.80 + (self.basic_salary - 166667) * 0.30

else:

wtax = 183541.80 + (self.basic_salary - 666667) * 0.35

return wtax

def get_total_deductions(self):
total_deductions = self.get_gsis_contrib() + self.get_philhealth_contrib() +
self.get_pagibig_contrib() + self.get_wtax()

return total_deductions

def get_gross_income(self):

gross_income = self.basic_salary - self.get_total_deductions()

return gross_income

def promote(self, new_position, new_basic_salary):


self.position = new_position

self.basic_salary = new_basic_salary

print("Employee promoted successfully.")

# Sample Employee Data

employees = [

EmployeePayroll("Thomas", "Cooper", "05/10/1979", "M", "Married", "Computer Engineer",


347983.33),

EmployeePayroll("Kirk", "Curry", "07/01/1985", "M", "Married", "Computer Network


Architect", 165241.67),

EmployeePayroll("Jesse", "Mitchell", "03/01/1980", "F", "Married", "Software Developer",


154808.33),

EmployeePayroll("Ashley", "Schmitt", "04/06/1992", "F", "Single", "Web developer",


77200.00),

EmployeePayroll("Raymond", "Warner", "02/19/1990", "M", "Single", "Animator", 68108.33)

def display_payroll():

print("First Name\tLast Name\tGSIS\tPHILHEALTH\tPag-IBIG\tWTAX\tGROSS


INCOME")
for emp in employees:

print(emp.first_name, emp.last_name, end="\t")

gsis = emp.get_gsis_contrib()

philhealth = emp.get_philhealth_contrib()

pagibig = emp.get_pagibig_contrib()

wtax = emp.get_wtax()

gross_income = emp.get_gross_income()

print(f"{gsis:.2f}\t{philhealth:.2f}\t{pagibig:.2f}\t{wtax:.2f}\t{gross_income:.2f}")

def display_employee_details():

for emp in employees:

print(f"Name: {emp.first_name} {emp.last_name}\nGender: {emp.gender}\nBirthday:


{emp.birthday.strftime('%m/%d/%Y')}\nCivil Status: {emp.civil_status}\nPosition:
{emp.position}\nBasic Salary: {emp.basic_salary:.2f}")

emp.get_age()

def promote_employee():

first_name = input("Enter employee's first name: ")

last_name = input("Enter employee's last name: ")

for emp in employees:

if emp.first_name == first_name and emp.last_name == last_name:

new_position = input("Enter new position: ")

new_basic_salary = float(input("Enter new basic salary: "))

emp.promote(new_position, new_basic_salary)

return

print("Employee not found.")

def update_name():
first_name = input("Enter employee's first name: ")

last_name = input("Enter employee's last name: ")

for emp in employees:

if emp.first_name == first_name and emp.last_name == last_name:

new_first_name = input("Enter new first name: ")

new_last_name = input("Enter new last name: ")

emp.first_name = new_first_name

emp.last_name = new_last_name

print("Name updated successfully.")


return

print("Employee not found.")

def update_civil_status():

first_name = input("Enter employee's first name: ")

last_name = input("Enter employee's last name: ")

for emp in employees:

if emp.first_name == first_name and emp.last_name == last_name:

new_civil_status = input("Enter new civil status: ")

emp.civil_status = new_civil_status

print("Civil status updated successfully.")

return

print("Employee not found.")

while True:

print("\n1. View Payroll\n2. View Employee Details\n3. Promote Employee\n4. Update


Name\n5. Update Civil Status\n6. Exit")

choice = input("Enter your choice: ")


if choice == "1":

display_payroll()

elif choice == "2":

display_employee_details()

elif choice == "3":

promote_employee()

elif choice == "4":

update_name()

elif choice == "5":


update_civil_status()

elif choice == "6":

print("Exiting...")

break

else:

print("Invalid choice. Please try again.")

You might also like