-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesting Class2 and OOP.py
78 lines (53 loc) · 1.66 KB
/
testing Class2 and OOP.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
class Employee:
def __init__(self, name, salary = 0):
self.name = name
self.salary = salary
def giveRaise(self, percent):
self.salary = self.salary + (self.salary * percent)
def work(self):
print(self.name, "I work")
def print_class(self):
return print("Class", type(self).__name__)
def __repr__(self):
return "name is: %s, salary: %s" % (self.name, self.salary)
class Chef(Employee):
def __init__(self, name, salary = 50000):
super().__init__(name, salary)
def work(self):
print(self.name, "I makes food")
class Server(Employee):
def __init__(self, name, salary = 25000):
super().__init__(name, salary)
def work(self):
print(self.name, "Interface for customer")
class PizzaBot(Chef):
def __init__(self, name, salary = 15000):
super().__init__(name, salary)
def work(self):
print(self.name, "Makes Pizza")
def main():
Bob = Employee("Bob", 30000) # Employee.__init__(name, salary)
Bob.giveRaise(0.20) # Employee.giveRaise()
Bob.work() # Employee.work()
Bob.print_class() # Employee.print_class()
print(Bob) # Employee.__repr__(name, salary)
print()
Anna = Chef("Anna")
Anna.work()
Anna.print_class()
print(Anna)
print()
Cris = Server("Cris")
Cris.work()
Cris.print_class()
print(Cris)
print()
MrRobot = PizzaBot("MrRobot")
MrRobot.work()
MrRobot.print_class()
print(MrRobot)
"""for klass in (Employee, Chef, Server, PizzaBot):
obj = klass(klass.__name__)
obj.work()"""
if __name__ == "__main__":
main()