-
Notifications
You must be signed in to change notification settings - Fork 273
Expand file tree
/
Copy pathApplication.java
More file actions
294 lines (260 loc) · 11.6 KB
/
Copy pathApplication.java
File metadata and controls
294 lines (260 loc) · 11.6 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
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
package subway;
import java.util.Scanner;
import subway.domain.Line;
import subway.domain.LineRepository;
import subway.domain.Station;
import subway.domain.StationRepository;
public class Application {
private static final String[] DEFAULT_STATIONS = { "교대역", "강남역", "역삼역", "남부터미널역", "양재역", "양재시민의숲역", "매봉역" };
private static final String[] DEFAULT_LINES = { "2호선", "3호선", "신분당선" };
private static final String MAIN_SELECT_MESSAGE = "## 메인화면\n" + "1. 역 관리\n" + "2. 노선 관리\n" + "3. 구간 관리\n"
+ "4. 지하철 노선도 출력" + "\n" + "Q. 종료\n" + "\n" + "## 원하는 기능을 선택하세요.";
private static final String STATION_SELECT_MESSAGE = "\n## 역 관리 화면\n" + "1. 역 등록\n" + "2. 역 삭제\n" + "3. 역 조회\n"
+ "B. 돌아가기" + "\n\n" + "## 원하는 기능을 선택하세요.";
private static final String LINE_SELECT_MESSAGE = "## 노선 관리 화면\r\n" + "1. 노선 등록\r\n" + "2. 노선 삭제\r\n"
+ "3. 노선 조회\r\n" + "B. 돌아가기\n" + "\n\n" + "## 원하는 기능을 선택하세요.";
private static final String STATION_LINE_MESSAGE = "## 구간 관리 화면\r\n" + "1. 구간 등록\r\n" + "2. 구간 삭제\r\n"
+ "B. 돌아가기\r\n" + "## 원하는 기능을 선택하세요.";
private static final String NEW_STATION_MESSAGE = "\n## 등록할 역 이름을 입력하세요.";
private static final String CREATE_STATION_MESSAGE = "[INFO] 지하철 역이 등록되었습니다.";
private static final String ERROR_CREATE_STATION_MESSAGE = "[ERROR] 이미 등록된 역 이름입니다.";
private static final String ERROR_CREATE_LENGHT_MESSAGE = "[ERROR] 2글자 이상에 이름만 가능합니다.";
private static final String DELETE_STATION_INPUT = "\n## 삭제할 역 이름을 입력하세요.";
private static final String DELETE_STATION_MESSAGE = "[INFO] 지하철 역이 삭제되었습니다.";
private static final String ERROR_DELETE_STATION_MESSAGE = "[ERROR] 없는 지하철역 이름입니다.";
private static final String NEW_LINE_MESSAGE = "\n## 등록할 노선 이름을 입력하세요.";
private static final String CREATE_LINE_MESSAGE = "[INFO] 지하철 노선이 등록되었습니다.";
private static final String ERROR_CREATE_LINE_MESSAGE = "[ERROR] 이미 등록된 노선 이름입니다.";
private static final String INPUT_START_LINE = "## 등록할 노선의 상행 종점역 이름을 입력하세요.";
private static final String INPUT_END_LINE = "## 등록할 노선의 하행 종점역 이름을 입력하세요.";
private static final String DELETE_LINE_INPUT = "\n## 삭제할 노선 이름을 입력하세요.";
private static final String DELETE_LINE_MESSAGE = "[INFO] 지하철 노선이 삭제되었습니다.";
private static final String ERROR_DELETE_LINE_MESSAGE = "[ERROR] 없는 지하철노선 이름입니다.";
private static final String INPUT_LINESTATION_LINE = "## 노선을 입력하세요.";
private static final String INPUT_LINESTATION_STATION = "## 역이름을 입력하세요.";
private static final String INPUT_LINESTATION_COUNT = "## 순서을 입력하세요.";
private static final String INPUT_LINESTATION_DELETE_LINE = "## 삭제할 구간의 노선을 입력하세요.";
private static final String INPUT_LINESTATION_DELETE__STATION = "## 삭제할 구간의 역을 입력하세요.";
private static final String ERROR_INPUT_MESSAGE = "[ERROR] 선택할 수 없는 기능입니다.";
private static final String END_PROGRAM_MESSAGE = "##프로그램을 종료합니다.";
public static void main(String[] args) {
final Scanner scanner = new Scanner(System.in);
// TODO: �봽濡쒓렇�옩 援ы쁽
StationRepository stationRepositiory = new StationRepository();
LineRepository lineRepositiory = new LineRepository();
defaultStation(stationRepositiory, lineRepositiory);
boolean end = false;
while (!end) {
System.out.println(MAIN_SELECT_MESSAGE);
end = selectMain(scanner, stationRepositiory, lineRepositiory);
}
}
private static void defaultStation(StationRepository stationRepositiory, LineRepository lineRepositiory) {
for (int defaultStation = 0; defaultStation < DEFAULT_STATIONS.length; defaultStation++) {
createStation(stationRepositiory, DEFAULT_STATIONS[defaultStation]);
}
for (int defaultLine = 0; defaultLine < DEFAULT_LINES.length; defaultLine++) {
createLine(lineRepositiory, DEFAULT_LINES[defaultLine]);
}
Line lineTwo = lineRepositiory.findStation("2호선");
lineTwo.startStation(stationRepositiory.findStation("교대역"));
lineTwo.endStation(stationRepositiory.findStation("역삼역"));
lineTwo.addStation(stationRepositiory, "강남역", 2);
Line lineThree = lineRepositiory.findStation("3호선");
lineThree.startStation(stationRepositiory.findStation("교대역"));
lineThree.endStation(stationRepositiory.findStation("매봉역"));
lineThree.addStation(stationRepositiory, "남부터미널역", 2);
lineThree.addStation(stationRepositiory, "양재역", 3);
Line lineNewBundang = lineRepositiory.findStation("신분당선");
lineNewBundang.startStation(stationRepositiory.findStation("강남역"));
lineNewBundang.endStation(stationRepositiory.findStation("양재시민의숲역"));
lineNewBundang.addStation(stationRepositiory, "양재역", 2);
}
public static Boolean selectMain(Scanner scanner, StationRepository stationRepositiory,
LineRepository lineRepositiory) {
String select = scanner.nextLine();
if (select.equals("1")) {
stationManagement(scanner, stationRepositiory, lineRepositiory);
return false;
}
if (select.equals("2")) {
lineManegement(scanner, stationRepositiory, lineRepositiory);
return false;
}
if (select.equals("3")) {
stationLineManagement(scanner, stationRepositiory, lineRepositiory);
return false;
}
if (select.equals("4")) {
showStatus(lineRepositiory);
return false;
}
if (select.equals("Q")) {
System.out.println(END_PROGRAM_MESSAGE);
return true;
}
System.out.println(ERROR_INPUT_MESSAGE);
return false;
}
public static StationRepository createStation(StationRepository stationRepositiory, String name) {
Station station = new Station(name);
stationRepositiory.addStation(station);
return stationRepositiory;
}
public static LineRepository createLine(LineRepository lineRepositiory, String name) {
Line line = new Line(name);
lineRepositiory.addLine(line);
return lineRepositiory;
}
public static void stationManagement(Scanner scanner, StationRepository stationRepositiory,
LineRepository lineRepositiory) {
while (true) {
System.out.println(STATION_SELECT_MESSAGE);
String Select = scanner.nextLine();
if (Select.equals("1")) {
newStation(scanner, stationRepositiory, lineRepositiory);
return;
}
if (Select.equals("2")) {
deleteStation(scanner, stationRepositiory, lineRepositiory);
return;
}
if (Select.equals("3")) {
statusStation(stationRepositiory);
return;
}
if (Select.equals("B")) {
return;
}
System.out.println(ERROR_INPUT_MESSAGE);
}
}
public static void newStation(Scanner scanner, StationRepository stationRepositiory,
LineRepository lineRepositiory) {
System.out.println(NEW_STATION_MESSAGE);
String station = scanner.nextLine();
if (stationRepositiory.findStation(station) == null) {
if (station.length() < 2) {
System.out.println(ERROR_CREATE_LENGHT_MESSAGE + "\n");
return;
}
createStation(stationRepositiory, station);
System.out.println(CREATE_STATION_MESSAGE + "\n");
return;
}
System.out.println(ERROR_CREATE_STATION_MESSAGE + "\n");
}
public static void deleteStation(Scanner scanner, StationRepository stationRepositiory,
LineRepository lineRepositiory) {
System.out.println(DELETE_STATION_INPUT);
String station = scanner.nextLine();
if (stationRepositiory.findStation(station) != null) {
stationRepositiory.deleteStation(station);
System.out.println(DELETE_STATION_MESSAGE + "\n");
return;
}
System.out.println(ERROR_DELETE_STATION_MESSAGE + "\n");
}
public static void statusStation(StationRepository stationRepositiory) {
stationRepositiory.viewStations();
}
public static void lineManegement(Scanner scanner, StationRepository stationRepositiory,
LineRepository lineRepositiory) {
while (true) {
System.out.println(LINE_SELECT_MESSAGE);
String Select = scanner.nextLine();
if (Select.equals("1")) {
newLine(scanner, stationRepositiory, lineRepositiory);
return;
}
if (Select.equals("2")) {
deleteLine(scanner, lineRepositiory);
return;
}
if (Select.equals("3")) {
statusLine(lineRepositiory);
return;
}
if (Select.equals("B")) {
return;
}
System.out.println(ERROR_INPUT_MESSAGE);
}
}
public static void newLine(Scanner scanner, StationRepository stationRepositiory, LineRepository lineRepositiory) {
System.out.println(NEW_LINE_MESSAGE);
String line = scanner.nextLine();
if (lineRepositiory.findStation(line) == null) {
if (line.length() < 2) {
System.out.println(ERROR_CREATE_LENGHT_MESSAGE + "\n");
return;
}
createLine(lineRepositiory, line);
Line tempLine = lineRepositiory.findStation(line);
System.out.println(INPUT_START_LINE);
String startLine = scanner.nextLine();
tempLine.startStation(stationRepositiory.findStation(startLine));
System.out.println(INPUT_END_LINE);
String endLine = scanner.nextLine();
tempLine.endStation(stationRepositiory.findStation(endLine));
System.out.println(CREATE_LINE_MESSAGE + "\n");
return;
}
System.out.println(ERROR_CREATE_STATION_MESSAGE + "\n");
}
public static void deleteLine(Scanner scanner, LineRepository lineRepositiory) {
System.out.println(DELETE_LINE_INPUT);
String line = scanner.nextLine();
if (lineRepositiory.findStation(line) != null) {
lineRepositiory.deleteLineByName(line);
System.out.println(DELETE_LINE_MESSAGE + "\n");
return;
}
System.out.println(ERROR_DELETE_LINE_MESSAGE + "\n");
}
public static void statusLine(LineRepository lineRepositiory) {
lineRepositiory.viewLine();
}
public static void stationLineManagement(Scanner scanner, StationRepository stationRepositiory,
LineRepository lineRepositiory) {
while (true) {
System.out.println(STATION_SELECT_MESSAGE);
String Select = scanner.nextLine();
if (Select.equals("1")) {
newStationLine(scanner, stationRepositiory, lineRepositiory);
return;
}
if (Select.equals("2")) {
deleteStationLine(scanner, stationRepositiory, lineRepositiory);
return;
}
if (Select.equals("B")) {
return;
}
System.out.println(ERROR_INPUT_MESSAGE);
}
}
public static void newStationLine(Scanner scanner, StationRepository stationRepositiory,
LineRepository lineRepositiory) {
System.out.println(INPUT_LINESTATION_LINE);
String line = scanner.nextLine();
System.out.println(INPUT_LINESTATION_STATION);
String station = scanner.nextLine();
System.out.println(INPUT_LINESTATION_COUNT);
String count = scanner.nextLine();
Line tempLine = lineRepositiory.findStation(line);
tempLine.addStation(stationRepositiory, station, Integer.parseInt(count));
}
public static void deleteStationLine(Scanner scanner, StationRepository stationRepositiory,
LineRepository lineRepositiory) {
System.out.println(INPUT_LINESTATION_DELETE_LINE);
String line = scanner.nextLine();
System.out.println(INPUT_LINESTATION_DELETE__STATION);
String station = scanner.nextLine();
Line tempLine = lineRepositiory.findStation(line);
tempLine.deleteStation(station);
}
public static void showStatus(LineRepository lineRepositiory) {
lineRepositiory.viewLineRepository();
}
}