-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoffee machine using oops
More file actions
114 lines (95 loc) · 3.4 KB
/
Copy pathcoffee machine using oops
File metadata and controls
114 lines (95 loc) · 3.4 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
class MenuItem:
def __init__(self, name, water, milk, coffee, cost):
self.name = name
self.cost = cost
self.ingredients = {
"water": water,
"milk": milk,
"coffee": coffee
}
class Menu:
def __init__(self):
self.menu = [
MenuItem(name="espresso", water=50, milk=0, coffee=18, cost=1.5),
MenuItem(name="latte", water=200, milk=150, coffee=24, cost=2.5),
MenuItem(name="cappuccino", water=250, milk=100, coffee=24, cost=3.0)
]
def get_items(self):
options = ""
for item in self.menu:
options += f"{item.name}/"
return options
def find_drink(self, order_name):
for item in self.menu:
if item.name == order_name:
return item
print("Sorry that item is not available.")
return None
class CoffeeMaker:
def __init__(self):
self.resources = {
"water": 300,
"milk": 200,
"coffee": 100,
}
def report(self):
print(f"Water: {self.resources['water']}ml")
print(f"Milk: {self.resources['milk']}ml")
print(f"Coffee: {self.resources['coffee']}g")
def is_resource_sufficient(self, drink):
can_make = True
for item in drink.ingredients:
if drink.ingredients[item] > self.resources[item]:
print(f"Sorry there is not enough {item}.")
can_make = False
return can_make
def make_coffee(self, order):
for item in order.ingredients:
self.resources[item] -= order.ingredients[item]
print(f"Here is your {order.name} ☕️. Enjoy!")
class MoneyMachine:
def __init__(self):
self.profit = 0
self.currency = "$"
def process_coins(self):
print("Please insert coins.")
total = int(input("how many quarters?: ")) * 0.25
total += int(input("how many dimes?: ")) * 0.1
total += int(input("how many nickles?: ")) * 0.05
total += int(input("how many pennies?: ")) * 0.01
return total
def make_payment(self, cost):
payment = self.process_coins()
if payment >= cost:
change = round(payment - cost, 2)
print(f"Here is {self.currency}{change} in change.")
self.profit += cost
return True
else:
print("Sorry that's not enough money. Money refunded.")
return False
def report(self):
print(f"Money: {self.currency}{self.profit}")
class CoffeeMachine:
def __init__(self):
self.menu = Menu()
self.coffee_maker = CoffeeMaker()
self.money_machine = MoneyMachine()
self.is_on = True
def run(self):
while self.is_on:
options = self.menu.get_items()
choice = input(f"What would you like? ({options}): ").lower()
if choice == "off":
self.is_on = False
elif choice == "report":
self.coffee_maker.report()
self.money_machine.report()
else:
drink = self.menu.find_drink(choice)
if drink:
if self.coffee_maker.is_resource_sufficient(drink):
if self.money_machine.make_payment(drink.cost):
self.coffee_maker.make_coffee(drink)
machine = CoffeeMachine()
machine.run()