-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathSubwayController.java
More file actions
95 lines (82 loc) · 3.23 KB
/
Copy pathSubwayController.java
File metadata and controls
95 lines (82 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
95
package subway.controller;
import subway.service.GraphService;
import subway.service.SubwayService;
import subway.util.message.InputMessage;
import subway.util.message.Menu;
import subway.view.InputView;
import subway.view.OutputView;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class SubwayController {
private final SubwayService subwayService;
private final GraphService graphService;
private final List<String> main = new ArrayList<>(List.of(Menu.SELECT_ROUTINE.getKey(), Menu.EXIT.getKey()));
private final List<String> routine = new ArrayList<>(List.of(Menu.SHORTEST_DISTANCE.getKey(), Menu.SHORTEST_TIME.getKey(), Menu.BACK.getKey()));
private int totalDistance;
private int totalTime;
private List<String> path;
public SubwayController(){
subwayService = new SubwayService();
graphService = new GraphService();
}
public void initSubway(){
subwayService.initSubway();
}
public void start(){
while(questionIsproceed()){
try{
questionRoutine();
} catch(IllegalArgumentException e){
OutputView.printMessage(e.getMessage());
questionRoutine();
}
}
}
private boolean questionIsproceed(){
OutputView.printMain();
String input = InputView.inputKey(main);
return confirmProceed(input);
}
private boolean confirmProceed(final String input){
if(input.equals(Menu.EXIT.getKey())){
return false;
}
return input.equals(Menu.SELECT_ROUTINE.getKey());
}
private void questionRoutine(){
OutputView.printRoutine();
String input = InputView.inputKey(routine);
questionMainNext(input);
}
private void questionMainNext(final String input){
if(input.equals(Menu.BACK.getKey())){
questionRoutine();
}
List<Integer> totalInfo = new ArrayList<>();
if(input.equals(Menu.SHORTEST_DISTANCE.getKey())){
totalInfo = getShortestDistance();
}
if(input.equals(Menu.SHORTEST_TIME.getKey())){
totalInfo = getShortestTime();
}
savetotalInfo(totalInfo);
OutputView.printResult(path, totalDistance, totalTime);
}
private List<Integer> getShortestDistance(){
String startStationInfo = InputView.inputStation(InputMessage.GET_START_STATION.getValue());
String endStationInfo = InputView.inputStation(InputMessage.GET_END_STARTION.getValue());
path = graphService.getShortestDistancePath(startStationInfo, endStationInfo);
return graphService.getTotalShortestDistanceAndShortestTime(path);
}
private List<Integer> getShortestTime(){
String startStationInfo = InputView.inputStation(InputMessage.GET_START_STATION.getValue());
String endStationInfo = InputView.inputStation(InputMessage.GET_END_STARTION.getValue());
path = graphService.getShortestTimePath(startStationInfo, endStationInfo);
return graphService.getTotalShortestDistanceAndShortestTime(path);
}
private void savetotalInfo(final List<Integer> totalInfo){
totalDistance = totalInfo.get(0);
totalTime = totalInfo.get(1);
}
}