-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserFunctions.cs
166 lines (155 loc) · 5.62 KB
/
UserFunctions.cs
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
using System;
using System.Threading;
using Ex03.GarageLogic;
namespace Ex03.ConsoleUI
{
public class UserFunctions
{
// $G$ NTT-999 (-3) This kind of field should be readonly.
private Garage m_Garage;
public UserFunctions()
{
m_Garage = new Garage();
}
public void ExecuteMenu()
{
Gui.PrintMenu();
int pick = Convert.ToInt32(Console.ReadLine());
eMenuOptions menuChoice;
menuChoice = (eMenuOptions)pick;
while (menuChoice != eMenuOptions.exit)
{
try
{
switch (menuChoice)
{
case eMenuOptions.AddVehicle:
addVehicleNavigator();
break;
case eMenuOptions.ShowAllReg:
showAllRegsNavigator();
break;
case eMenuOptions.ChangeStateOfVehicle:
changeStateNavigator();
break;
case eMenuOptions.FillAirToMax:
fillAirNavigator();
break;
case eMenuOptions.FillFuel:
fillFuelNavigator();
break;
case eMenuOptions.ChargeEnergy:
chargeBatteryNavigator();
break;
case eMenuOptions.ShowVehicleDetails:
showVehicleDetailsNavigator();
break;
case eMenuOptions.exit:
break;
default:
Gui.MyWriteLine("invalid input, choose a number between 1 to 8");
break;
}
}
catch (FormatException formatException)
{
Gui.MyWriteLine(formatException.Message);
}
catch (ArgumentException argumentException)
{
Gui.MyWriteLine(argumentException.Message);
}
catch (ValueOutOfRangeException valueOutOfRangeException)
{
Gui.MyWriteLine(valueOutOfRangeException.Message);
}
catch (Exception exception)
{
Gui.MyWriteLine(exception.Message);
}
Console.Clear();
Gui.PrintMenu();
pick = Convert.ToInt32(Console.ReadLine());
menuChoice = (eMenuOptions)pick;
}
}
private void showVehicleDetailsNavigator()
{
string regNumber = Gui.GetRegNumber();
string output = m_Garage.ShowVehicleDetails(regNumber);
Console.WriteLine(output);
Console.ReadKey();
}
private void chargeBatteryNavigator()
{
float amount = 0;
string regNumber = Gui.GetRegNumber();
amount = Gui.GetAmountToChargeBattery();
m_Garage.ChargeEnergy(regNumber, amount);
Gui.Done();
}
private void fillFuelNavigator()
{
float amount = 0;
string regNumber = Gui.GetRegNumber();
eFuelType fuel = Gui.GetFuelTypeAndAmount(ref amount);
m_Garage.FillFuel(regNumber, fuel, amount);
Gui.Done();
}
private void changeStateNavigator()
{
string regNumber = Gui.GetRegNumber();
eVehicleState toChange = Gui.GetVehicleState();
GarageItem temp = m_Garage.ChangeStateOfVehicle(regNumber, toChange);
Gui.ChangeStateVerification(temp);
}
private void addVehicleNavigator()
{
GarageItem garageItem = Gui.GetGarageItem();
bool res = m_Garage.AddVehicle(garageItem);
Gui.AddVehicleVerification(garageItem, res);
}
private void showAllRegsNavigator()
{
string s = "";
int UserChose =
Gui.UserChoosingMessage
("Press 1 to show all regs numbers in system, else to show all cars with specific state");
if (UserChose == 1)
{
s += m_Garage.ShowAllReg();
}
else
{
eVehicleState toShow = Gui.GetVehicleState();
s += m_Garage.ShowAllRegByState(toShow);
}
Gui.MyWriteLine(s);
}
private void fillAirNavigator()
{
string regNumber = Gui.GetRegNumber();
GarageItem temp = null;
int UserChose =
Gui.UserChoosingMessage
("Press 1 to fill up limited amount of air, else filling up to maximum air pressure");
if (UserChose == 1)
{
float amount = Gui.GetAmountToFillWheels();
try
{
temp = m_Garage.FillAir(regNumber, amount);
}
catch (ValueOutOfRangeException ex)
{
throw ex;
}
}
else
{
temp = m_Garage.FillAirToMax(regNumber);
}
Gui.FillAirVerification(temp);
}
}
}