-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathMainController.java
More file actions
63 lines (57 loc) · 2.45 KB
/
Copy pathMainController.java
File metadata and controls
63 lines (57 loc) · 2.45 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
package subway.controller;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import subway.domain.Line;
import subway.domain.LineRepository;
import subway.domain.Station;
import subway.domain.StationRepository;
import subway.view.InputView;
import subway.view.OutputView;
import utils.LineUtils;
public class MainController {
private static final List<String> EXIT_SIGN = Arrays.asList("q", "Q");
private static final int START = 1;
private static final int MENU_END = 1;
private MainController() {
}
public static void runSubwayPath(Scanner scanner) {
init();
System.out.println(LineRepository.lines().get(0).getTerminals().get(0).getName());
String selection;
do {
OutputView.printMenu(LineUtils.MAIN_MENU);
selection = InputView.inputSelection(scanner);
executeSelection(scanner, selection);
} while (!EXIT_SIGN.contains(selection));
}
private static void init() {
LineRepository.addLine(new Line("2호선",
Arrays.asList(StationRepository.findStation("교대역"), StationRepository.findStation("강남역"), StationRepository.findStation("역삼역")),
Arrays.asList(2, 2),
Arrays.asList(3, 3)));
LineRepository.addLine(new Line("3호선",
Arrays.asList(StationRepository.findStation("교대역"), StationRepository.findStation("남부터미널역"), StationRepository.findStation("양재역"), StationRepository.findStation("매봉역")),
Arrays.asList(3, 6, 1),
Arrays.asList(2, 5, 1)));
LineRepository.addLine(new Line("신분당선",
Arrays.asList(StationRepository.findStation("강남역"), StationRepository.findStation("양재역"), StationRepository.findStation("양재시민의숲역")),
Arrays.asList(2, 10),
Arrays.asList(8, 3)));
}
// TODO 검증 나누기
private static void executeSelection(Scanner scanner, String selection) {
try {
int selectedNumber = Integer.parseInt(selection);
if (START > selectedNumber || selectedNumber > MENU_END){
throw new IllegalArgumentException();
}
PathController.pathSearch(scanner);
} catch (IllegalArgumentException e) {
if (EXIT_SIGN.contains(selection)) {
return;
}
System.out.println(LineUtils.ERROR_INVALID_TYPE);
}
}
}