-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses_task.py
More file actions
142 lines (113 loc) · 3.12 KB
/
classes_task.py
File metadata and controls
142 lines (113 loc) · 3.12 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import sys
from datetime import date
import time
normal_emp_list = []
manager_list = []
class Employee:
def __init__(self,name,age,salary,emplyment_date):
self.name = name
self.age = age
self.salary = salary
self.emplyment_date = emplyment_date
def __str__(self):
return "Name: %s, Age: %s, Salary: %s KWD, Working for: %s year(s)" % (self.name,self.age,round(self.salary,3), self.get_working_years())
def get_working_years(self):
today = date.today()
return today.year - int(self.emplyment_date)
class Manager(Employee):
def __init__(self, name, age, salary,emplyment_date,bonus_percentage):
Employee.__init__(self,name,age,salary,emplyment_date)
self.bonus_percentage = bonus_percentage
def get_bonus(self):
return round(((self.bonus_percentage/100) * self.salary),3)
def __str__(self):
return "Name: %s, Age: %s, Salary: %s KWD, Working for: %s year(s), BONUS: %f KWD" % (self.name,self.age,self.salary, self.get_working_years(), self.get_bonus())
def show_list(list_name):
if list_name == manager_list:
for emp in list_name:
print(emp)
print(" ")
else:
for emp in list_name:
print(emp)
print(" ")
def add_emp(class_name):
name = input("Name: ")
age = int(input("Age: "))
salary = float(input("Salary: "))
if class_name == Manager:
bonus_percentage= int(input("Bonus Percentage (%): "))
emplyment_date= int(input("Empolyment Year: "))
print("ADDED!")
else:
emplyment_date= int(input("Empolyment Year: "))
print("ADDED!")
if class_name == Manager:
emp = class_name(name,age,salary,emplyment_date,bonus_percentage)
manager_list.append(emp)
else:
emp = class_name(name,age,salary,emplyment_date)
normal_emp_list.append(emp)
print("""
SUSHI & Co. Data Entry Program
===============================
ACTIONS AVAIABLE TO HR EMPLOYEE:
Type number 1 for.. SHOW all Employees
Type number 2 for.. SHOW all Managers
Type number 3 for.. ADD an Employee
Type number 4 for.. ADD a Manager
Type number 5 for.. EXIT PROGRAM
""")
while True:
try:
user_input = int(input("(0) for help..>"))
except ValueError:
print("Invaild Entry")
else:
if user_input == 1:
print("""
**********EMPLOYEES LIST**********
""")
print(" ")
show_list(normal_emp_list)
print("""
Total: {} employee(s)
""".format(len(normal_emp_list)))
continue
elif user_input == 2:
print(""""
_________MANAGERS LIST__________
""")
show_list(manager_list)
print("""
Total: {} manager(s)
""".format(len(manager_list)))
continue
elif user_input == 3:
print("""
[ADDING AN EMPLOYEE]
""")
add_emp(Employee)
continue
elif user_input == 4:
print("""
[ADDING A MANAGER]
""")
add_emp(Manager)
continue
elif user_input == 5:
print("CLOSING PROGRAM...")
sys.exit(0)
elif user_input == 0:
print("""ACTIONS AVAIABLE TO HR EMPLOYEE:
Type number 1 for.. SHOW all Employees
Type number 2 for.. SHOW all Managers
Type number 3 for.. ADD an Employee
Type number 4 for.. ADD a Manager
Type number 5 for.. EXIT PROGRAM""")
continue
else:
print("""
Invaild input! TRY AGAIN
""")
continue