-
Notifications
You must be signed in to change notification settings - Fork 0
/
employee.py
58 lines (44 loc) · 1.36 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
52
53
54
55
56
57
#!/usr/bin/env python
# TriTek programming test implemented in Python 2.x
class Employee:
"""A simple employee class."""
# used at class level only not on instances
empCount = 0
# Constructor method
def __init__(self, firstName, lastName):
self.firstName = firstName
self.lastName = lastName
self.id = Employee.empCount
Employee.empCount += 1
self.sub = []
self.mgr = []
# setters
def setmanager(self, manager):
self.mgr.append(manager)
manager.sub.append(self)
def setsub(self, subordinate):
self.sub.append(subordinate)
subordinate.mgr.append(self)
# print methods (getters)
def printsubs(self):
if self.sub:
for s in self.sub:
print s.firstName, s.lastName
def printallsubs(self):
if self.sub:
for s in self.sub:
print s.firstName, s.lastName
s.printallsubs() # recurse
def printmgrs(self):
if self.mgr:
for m in self.mgr:
print m.firstName, m.lastName
# Test w/ 4 employees
joe = Employee("Joe", "Cool")
sam = Employee("Sam", "Smith")
frank = Employee("Frank", "Daboss")
lisa = Employee("Lisa", "Noob")
# Frank manages Joe and Sam; Joe manages Lisa
frank.setsub(joe)
frank.setsub(sam)
joe.setsub(lisa)