-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathPathController.java
More file actions
59 lines (50 loc) · 1.74 KB
/
Copy pathPathController.java
File metadata and controls
59 lines (50 loc) · 1.74 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
package subway.controller;
import subway.domain.SearchType;
import subway.dto.ShortestPathDto;
import subway.service.PathService;
import subway.view.InputView;
import subway.view.OutputView;
public class PathController {
private static final String START = "시작";
private static final String END = "도착";
private final InputView inputView;
private final PathService pathService;
public PathController(InputView inputView) {
this.inputView = inputView;
pathService = new PathService();
}
public void run() {
OutputView.printPathScreen(SearchType.getInfos());
SearchType searchType = requestSearchNumber();
runDetailAction(searchType);
}
private SearchType requestSearchNumber() {
SearchType searchType = SearchType.BACK;
while (true) {
try {
searchType = inputView.inputSearchNumber();
break;
} catch (Exception e) {
System.out.println(e.getMessage());
OutputView.printPathScreen(SearchType.getInfos());
}
}
return searchType;
}
private void runDetailAction(SearchType searchType) {
if (searchType.isBack()) {
return;
}
String startStationName = inputView.inputStationName(START);
String endStationName = inputView.inputStationName(END);
while (true) {
try {
ShortestPathDto shortestPathDto = pathService.calcShortestPath(startStationName, endStationName, searchType);
OutputView.printResult(shortestPathDto);
break;
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
}