-
Notifications
You must be signed in to change notification settings - Fork 0
/
employee.py
53 lines (42 loc) · 1.97 KB
/
employee.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class Employee:
""" Initialize variables"""
def __init__(self):
self.__name = " "
self.__designation = 0
self.__salary = 0
"""All the getters and setters are used because we use private variables with __"""
"""The set_name method sets the set_name attribute"""
def set_name(self, name):
self.__name = name
"""The set_designation method sets the set_designation attribute"""
def set_designation(self, designation):
self.__designation = designation
"""The set_salary method sets the set_salary attribute"""
def set_salary(self, salary):
self.__salary = salary
""""The get_name method it the returns the name attribute"""
def get_name(self):
return self.__name
"""The get_designation method it returns the designation attribute"""
def get_designation(self):
return self.__designation
"""The get_salary method it returns the salary attribute"""
def get_salary(self):
return self.__salary
"""Calculate the bonus based on input from the user, calls get_designation method"""
def __calculate_bonus(self):
if Employee.get_designation(self) == 1:
return 0.10 * Employee.get_salary(self)
elif Employee.get_designation(self) == 2:
return 0.15 * Employee.get_salary(self)
elif Employee.get_designation(self) == 3:
return 0.20 * Employee.get_salary(self)
"""Calculates the total salary by calling the calculate_bonus and get_salary methods and adding them"""
def total_salary(self):
return Employee.__calculate_bonus(self) + Employee.get_salary(self)
"""Used for printing the current state of the variables, it also calls various methods above"""
def __str__(self):
return "Name: {}\nBonus: {:.2f}\nTotal Salary: {:.2f}\n" \
.format(Employee.get_name(self),
Employee.__calculate_bonus(self),
Employee.total_salary(self), 2)