-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.py
57 lines (39 loc) · 1.3 KB
/
class.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
52
53
54
55
56
class Employee:
raise_amount = 1.04
num_of_emps = 0
def __init__(self, first, last, pay):
self.first = first
self.last = last
self.email = first + '.' + last + '@company.com'
Employee.num_of_emps += 1
def fullName(self):
return '{} {}'.format(self.first, self.last)
def applyRaise(self):
self.pay = int(self.pay * self.raise_amount)
class Developer(Employee):
raise_amt = 1.10
def __init__(self, first, last, pay, prog_lang):
super().__init__(first, last, pay)
self.prog_lang = prog_lang
class Manager(Employee):
def __init__(self, first, last, pay, employees=None):
if employees is None:
employees = []
else:
self.employees = employees
def add_emp(self, emp):
if emp not in self.employees:
self.employees.append(emp)
def remove_emp(self, emp):
if emp in self.employees:
self.employees.remove(emp)
def print_emps(self):
for emp in self.employees:
print('-->', self.fullname())
dev_1 = Developer('John', 'Doe', 5000, 'Python')
dev_2 = Developer('Jane', 'Doe', 6000, 'Java')
mgr_1 = Manager('Sue', 'Smith', 9000, [dev1])
print(mgr_1.email)
mgr_1.add_emp(dev1)
mgr_1.remove_emp(dev1)
mgr_1.print_emps()