-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathPathManage.java
More file actions
60 lines (52 loc) · 2.09 KB
/
Copy pathPathManage.java
File metadata and controls
60 lines (52 loc) · 2.09 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
package subway;
import subway.domain.*;
import subway.view.*;
import java.util.List;
import java.util.Scanner;
import static subway.Application.startProgram;
public class PathManage {
public static void managePath(Scanner kbd) {
View.showPathMenu();
String input = InputView.inputFunction(kbd, Constants.SUB_FUNCTIONS);
if (input.equals(Constants.MIN_DISTANCE))
findMinDistance(kbd);
if (input.equals(Constants.MIN_TIME))
findMinTime(kbd);
if (input.equals(Constants.GO_BACK_MENU))
startProgram(kbd);
}
public static void findMinDistance(Scanner kbd) {
try {
String[] stations = InputView.inputSrcDest(kbd);
List<String> shortestPath = Init.dijkstraDistance.getPath(stations[0], stations[1]).getVertexList();
showMinPath(Constants.PATH_DISTANCE, shortestPath, getMinValue(stations));
startProgram(kbd);
} catch (Exception e) {
startProgram(kbd);
}
}
public static void findMinTime(Scanner kbd) {
try {
String[] stations = InputView.inputSrcDest(kbd);
List<String> shortestPath = Init.dijkstraTime.getPath(stations[0], stations[1]).getVertexList();
showMinPath(Constants.PATH_TIME, shortestPath, getMinValue(stations));
startProgram(kbd);
} catch (Exception e) {
startProgram(kbd);
}
}
public static void showMinPath(String name, List<String> path, int[] values) {
Line minPath = new Line(name);
LineRepository.addLine(minPath, path);
View.displayPath(minPath, values[0], values[1]);
LineRepository.deleteLineByName(name);
}
public static int[] getMinValue(String[] stations) {
double time = Init.dijkstraTime.getPath(stations[0], stations[1]).getWeight();
double distance = Init.dijkstraDistance.getPath(stations[0], stations[1]).getWeight();
int[] values = new int[2];
values[0] = (int) Math.round(time);
values[1] = (int) Math.round(distance);
return values;
}
}