forked from lemesh2424/python_lab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.py
More file actions
115 lines (97 loc) · 3.12 KB
/
Copy pathmenu.py
File metadata and controls
115 lines (97 loc) · 3.12 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
115
from station import Station
from serialization import Serialization
from fuel import Fuel
class Menu:
def __init__(self, station):
self.__station__ = station
def print(self):
option = ''
while True:
print("_______MENU_______\n")
print('[a]dd fuel')
print('[s]pent fuel from some station')
print('[d]elete fuel')
print('[i]mport to JSON')
print('[e]xport from JSON')
print("[p]rint station")
print('[e]xit')
print("input option: ")
option = input()
print('\n' * 80)
if option == 'a':
self.optionAdd()
elif option == 's':
self.optionSpent()
elif option == 'd':
self.optionDelete()
elif option == 'i':
self.optionSave()
elif option == 'e':
self.optionLoad()
elif option == 'p':
self.optionPrint()
elif option == 'e':
print("BYE!")
return
else:
print("Input menu option")
print('\n' * 3)
def optionAdd(self):
print("Input fuel name")
name = input()
if self.__station__.isFuel(name):
print('Fuel already exist')
return
print("Input fuel tank")
tank = input()
try:
tank = int(tank)
except ValueError:
print("Tank must be a number!")
return
if type(tank) == int:
self.__station__.addFuel(Fuel(name, tank))
print("Successfully added!")
else:
print("Tank must a number!")
def optionSpent(self):
self.optionPrint()
print("\n\nInput fuel name that you want to spent: ")
name = input()
if self.__station__.isFuel(name):
print("Input spending volume")
volume = input()
try:
volume = int(volume)
except ValueError:
print("Volume must be a number!")
return
self.__station__.spentFuel(name, volume)
print("Spent!")
else:
print("Fuel with name " + name + " not found")
def optionDelete(self):
self.optionPrint()
print("\n\nInput fuel name that you want to delete: ")
name = input()
if self.__station__.isFuel(name):
self.__station__.deleteFuel(name)
else:
print("Fuel with name " + name + " not found")
def optionLoad(self):
s = Serialization()
self.__station__ = s.load()
print('Successfully exported')
def optionSave(self):
s = Serialization()
s.save(self.__station__)
print('Successfully imported')
def optionPrint(self):
print("#########")
if self.__station__.isEmpty():
print("Station is empty")
else:
formattedList = self.__station__.showFormattedFuelList()
for f in formattedList:
print(f)
print("#########")