-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
108 lines (78 loc) · 3.29 KB
/
Copy pathmain.py
File metadata and controls
108 lines (78 loc) · 3.29 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
from menu import Menu, MenuItem
from coffee_maker import CoffeeMaker
from money_machine import MoneyMachine
from graphics import SystemGraphics
#globals
ACTIVE = True;
DORMANT = False;
DRINKS = ["espresso","latte","cappuccino"];
Price = 0;
def generate_report(coffeeObject):
if isinstance(coffeeObject, CoffeeMaker):
coffeeObject.report();
def find_drinkObject(requested_drink, menu):
"""
returns the object that matches the drink requested.
"""
#find the drink that matches the drinkObj name
return menu[requested_drink];
def run_software():
#Object instantiation:
coffee_handler = CoffeeMaker();
finance_handler = MoneyMachine();
system = SystemGraphics();
coffee_resources = Menu();
## Explanation:
# returns an obj of menuItem-> of type espresso, the construtor then deals with arranging the data by destructuring the MenuItem obj into its attributes;
espresso = coffee_resources.find_drink('espresso');
#same thing occures here but for latte.
latte = coffee_resources.find_drink('latte');
#same thing occures here but for cappuccino.
cappuccino = coffee_resources.find_drink('cappuccino');
the_menu = {
'espresso': espresso,
'latte': latte,
'cappuccino': cappuccino,
}
machine_status = ACTIVE;
#UI stuff
system.display_welcome_screen();
while(machine_status):
system.display_static_logo();
command = input("\ntype:\n'espresso'\n'latte'\n'cappuccino'\nto make your drink.\n************************\n************************\ntype 'help' for other commands. \n>> ").lower();
if command == "help":
#UI stuff
system.display_help_section();
run_software();
elif command == "report":
#UI stuff
system.display_report(coffeeMakerObject=coffee_handler);
generate_report(coffee_handler);
pass;
elif command == "off":
#UI stuff
system.display_shutdown();
machine_status = False; #switching off the system.
break;
elif command in DRINKS:
system.display_initial_report(coffeeMakerObject= coffee_handler);
#find the drink that matches the drinkObj name
drink = find_drinkObject(command,the_menu)
#checking if there are enough resources to make the drink.
if coffee_handler.is_resource_sufficient(drink):
#prompting user to insert coins
system.display_payment_section();
user_cost = finance_handler.process_coins(drink);
transaction_status = finance_handler.make_payment(user_cost, drink);
if transaction_status:
#update report in money machine by updating the profit
# finance_handler.profit += user_cost; handled in make_payement
coffee_handler.make_coffee(drink);
system.display_final_report(coffeeMakerObject=coffee_handler);
else:
print("payment was not accepted.");
else:
print(f"not enough resources to make {command}");
system.restart_system();
pass;
run_software();