forked from psounis/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise09.py
More file actions
60 lines (42 loc) · 1.52 KB
/
exercise09.py
File metadata and controls
60 lines (42 loc) · 1.52 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
from random import randrange, seed
from datetime import datetime
from abc import ABC, abstractmethod
class Person(ABC):
def __init__(self, full_name, salary):
self.full_name = full_name
self.salary = salary
self.served_cnt = 0
def report(self):
print(self.full_name + " served " + str(self.served_cnt) + " customers.")
class Waiter(Person):
def __init__(self, full_name, salary):
Person.__init__(self, full_name, salary)
def serve(self, customers, barista):
self.served_cnt += customers
print("Waiter " + self.full_name + " served " + str(customers) + " customers")
barista.prepare(customers)
class Barista(Person):
def __init__(self, full_name, salary):
Person.__init__(self, full_name, salary)
def prepare(self, customers):
print("Barista " + self.full_name + " served " + str(customers) + " customers")
self.served_cnt += customers
class Owner(Waiter, Barista):
def __init__(self, full_name, salary):
Person.__init__(self, full_name, salary)
def main():
seed(datetime.now())
o = Owner("owner", 100000)
w1 = Waiter("waiter-1", 200000)
w2 = Waiter("waiter-1", 200000)
b = Barista("barista", 300000)
waiters = [o, w1, w2]
baristas = [o, b]
for _ in range(10):
waiters[randrange(3)].serve(randrange(1,5+1), baristas[randrange(2)])
print("")
o.report()
w1.report()
w2.report()
b.report()
main()