-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathMainView.java
More file actions
94 lines (81 loc) · 3.23 KB
/
Copy pathMainView.java
File metadata and controls
94 lines (81 loc) · 3.23 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
package subway.Views;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Scanner;
import subway.Controller.SubwayRouteSearcher;
import subway.utils.ErrorValidator;
public class MainView {
private final static List<String> MAINSELECTLIST = Arrays.asList("1", "Q");
private final static List<String> ROUTESELECTLIST = Arrays.asList("1", "2", "B");
public static void printMainScreen(Scanner scanner) {
OutputView.printMainSelection();
String userMainSelection = InputView.getUserInput(scanner);
System.out.println();
checkUserInput(scanner, userMainSelection, MAINSELECTLIST);
SubwayRouteSearcher.selectMain(scanner, userMainSelection);
}
public static void printRouteScreen(Scanner scanner) {
OutputView.printRouteSelection();
String userRouteSelection = InputView.getUserInput(scanner);
System.out.println();
checkUserInput(scanner, userRouteSelection, ROUTESELECTLIST);
SubwayRouteSearcher.selectRoute(scanner, userRouteSelection);
}
public static void printResultScreen(Scanner scanner, List<String> resultList) {
OutputView.printResultRoute(resultList);
System.out.println();
MainView.printMainScreen(scanner);
}
private static void checkUserInput(Scanner scanner, String userSelection,
List<String> SELECTLIST) {
try {
ErrorValidator.checkMainSelection(SELECTLIST, userSelection);
} catch (InputMismatchException e) {
System.out.println(e.getMessage());
System.out.println();
printMainScreen(scanner);
}
}
public static String printStartStation(Scanner scanner) {
String startStaion = InputView.getStartStation(scanner);
System.out.println();
checkStartStation(scanner, startStaion);
return startStaion;
}
public static String printEndStation(Scanner scanner, String startStation) {
String endStaion = InputView.getEndStation(scanner);
System.out.println();
checkEndStation(scanner, endStaion);
checkStartEndStation(scanner, startStation, endStaion);
return endStaion;
}
private static void checkStartEndStation(Scanner scanner, String startStation,
String endStaion) {
try {
ErrorValidator.checkStartEndStation(startStation, endStaion);
} catch (InputMismatchException e) {
System.out.println(e.getMessage());
System.out.println();
printMainScreen(scanner);
}
}
private static void checkStartStation(Scanner scanner, String startStaion) {
try {
ErrorValidator.checkStationRepository(startStaion);
} catch (InputMismatchException e) {
System.out.println(e.getMessage());
System.out.println();
printMainScreen(scanner);
}
}
private static void checkEndStation(Scanner scanner, String endStaion) {
try {
ErrorValidator.checkStationRepository(endStaion);
} catch (InputMismatchException e) {
System.out.println(e.getMessage());
System.out.println();
printMainScreen(scanner);
}
}
}