-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEngineerMenu.cs
168 lines (148 loc) · 5.76 KB
/
EngineerMenu.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
167
168
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MetroMap
{
public class EngineerMenu
{
private StationGraph stationGraph;
public EngineerMenu(StationGraph stationGraph)
{
this.stationGraph = stationGraph;
}
public void DisplayMenu()
{
Console.WriteLine("Metro Map Engineer Menu");
Console.WriteLine("1. View Traffic Info");
Console.WriteLine("2. View Stations");
Console.WriteLine("3. Add Delay Time");
Console.WriteLine("4. Remove Delay Time");
Console.WriteLine("5. Change track Status (open/close)");
Console.WriteLine("6. Exit");
Console.Write("Enter your choice: ");
int choice;
while (!int.TryParse(Console.ReadLine(), out choice) || choice < 1 || choice > 6)
{
Console.WriteLine("Invalid choice. Please enter a number between 1 and 6.");
Console.Write("Enter your choice: ");
}
switch (choice)
{
case 1:
ViewTrafficInfo();
break;
case 2:
ViewStations();
break;
case 3:
AddDelay();
break;
case 4:
RemoveDelay();
break;
case 5:
ChangeTrackStatus();
break;
case 6:
Console.WriteLine("Exiting...");
break;
}
}
public void ViewTrafficInfo()
{
Console.WriteLine("List of closed track sections:");
foreach (Edge edge in stationGraph.Edges)
{
if (edge.IsClosed)
{
Console.WriteLine($" From {edge.From.Name} To {edge.To.Name}");
}
}
}
public void ViewStations()
{
foreach (var line in stationGraph.Lines)
{
Console.WriteLine($"Line: {line.Name} ({line.Direction})");
foreach (var station in line.Stations)
{
Console.WriteLine($" {station.Name}");
}
}
}
public void AddDelay()
{
Console.WriteLine("Enter the name of the first station:");
string firstStationName = Console.ReadLine();
Console.WriteLine("Enter the name of the second station:");
string secondStationName = Console.ReadLine();
Console.WriteLine("Enter the delay time (in minutes):");
double delayTime;
// Validates the delay input as a double
while (!double.TryParse(Console.ReadLine(), out delayTime) || delayTime < 0)
{
Console.WriteLine("Invalid input. Please enter a valid number for delay time:");
}
// Find the edge
Edge edge = stationGraph.Edges.FirstOrDefault(e => e.From.Name.Equals(firstStationName, StringComparison.OrdinalIgnoreCase)
&& e.To.Name.Equals(secondStationName, StringComparison.OrdinalIgnoreCase));
if (edge != null)
{
// Add delay
edge.Delay += delayTime;
Console.WriteLine($"Added {delayTime} minutes of delay between {firstStationName} and {secondStationName}.");
}
else
{
Console.WriteLine("No direct edge found between the specified stations.");
}
}
public void RemoveDelay()
{
Console.WriteLine("Enter the name of the first station:");
string firstStationName = Console.ReadLine();
Console.WriteLine("Enter the name of the second station:");
string secondStationName = Console.ReadLine();
// Find the edge
Edge edge = stationGraph.Edges.FirstOrDefault(e => e.From.Name.Equals(firstStationName, StringComparison.OrdinalIgnoreCase)
&& e.To.Name.Equals(secondStationName, StringComparison.OrdinalIgnoreCase));
if (edge != null)
{
// Add delay
edge.Delay = 0;
Console.WriteLine($"Removed delay between {firstStationName} and {secondStationName}.");
}
else
{
Console.WriteLine("No direct edge found between the specified stations.");
}
}
public void ChangeTrackStatus()
{
Console.WriteLine("Enter the name of the first station:");
string firstStationName = Console.ReadLine();
Console.WriteLine("Enter the name of the second station:");
string secondStationName = Console.ReadLine();
// Find the edge
Edge edge = stationGraph.Edges.FirstOrDefault(e => e.From.Name.Equals(firstStationName, StringComparison.OrdinalIgnoreCase)
&& e.To.Name.Equals(secondStationName, StringComparison.OrdinalIgnoreCase));
if (edge != null)
{
if (edge.IsClosed)
{
edge.IsClosed = false;
}
else
{
edge.IsClosed = true;
}
Console.WriteLine($"Track status changed between {firstStationName} and {secondStationName}.");
}
else
{
Console.WriteLine("No direct edge found between the specified stations.");
}
}
}
}