-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCarUI.java
More file actions
127 lines (107 loc) · 4.65 KB
/
CarUI.java
File metadata and controls
127 lines (107 loc) · 4.65 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import java.util.Scanner;
public class CarUI {
AutonomousCarController autonomousCarController;
public void setDependencies(AutonomousCarController autonomousCarController){
this.autonomousCarController = autonomousCarController;
}
public void start() {
Integer exitStatus = 0;
while (exitStatus == 0) {
this.displayOptions();
exitStatus = this.readOption();
}
System.out.println("Exiting Car UI!");
}
public void displayOptions() {
System.out.println("Welcome to the car!");
System.out.println("Choose from the following options:");
System.out.println("1. Start a trip");
System.out.println("2. Start the car");
System.out.println("3. Exit car UI");
}
public Integer readOption() {
Scanner scan = new Scanner(System.in);
Scanner scanner = new Scanner(System.in);
System.out.println("Please select your option:");
int choice = scan.nextInt();
switch (choice) {
case 1:
System.out.println("Enter start and end location (Geo Points)");
GeoPoint startLoc = new GeoPoint();
System.out.println("Start Location - latitude:");
double start_location_lat = scanner.nextDouble();
System.out.println("Start Location - longitude:");
double start_location_long = scanner.nextDouble();
startLoc.setLat(start_location_lat);
startLoc.setLon(start_location_long);
GeoPoint endLoc = new GeoPoint();
System.out.println("End Location - latitude:");
double end_location_lat = scanner.nextDouble();
System.out.println("End Location - longitude:");
double end_location_long = scanner.nextDouble();
endLoc.setLat(end_location_lat);
endLoc.setLon(end_location_long);
autonomousCarController.trip(startLoc, endLoc);
break;
case 2:
//autonomousCarController.start();
System.out.println("Select input type for starting the car:");
System.out.println("1. Manual");
System.out.println("2. Voice");
System.out.println("3. Touch");
System.out.println("4. Remote");
int inputType = scan.nextInt();
switch (inputType) {
case 1:
autonomousCarController.setStartStrategy(new ManualStartStrategy());
break;
case 2:
autonomousCarController.setStartStrategy(new VoiceStartStrategy());
break;
case 3:
autonomousCarController.setStartStrategy(new TouchStartStrategy());
break;
case 4:
autonomousCarController.setStartStrategy(new RemoteStartStrategy());
break;
default:
System.out.println("Invalid input type selected");
return 0;
}
autonomousCarController.startVehicle();
break;
case 3:
//return 1;
System.out.println("Select input type for starting the car:");
System.out.println("1. Manual");
System.out.println("2. Voice");
System.out.println("3. Touch");
System.out.println("4. Remote");
int inputType = scan.nextInt();
switch (inputType) {
case 1:
autonomousCarController.setStopStrategy(new ManualStopStrategy());
break;
case 2:
autonomousCarController.setStopStrategy(new VoiceStopStrategy());
break;
case 3:
autonomousCarController.setStopStrategy(new TouchStopStrategy());
break;
case 4:
autonomousCarController.setStopStrategy(new RemoteStopStrategy());
break;
default:
System.out.println("Invalid input type selected");
return 0;
}
autonomousCarController.stopVehicle();
break;
case 4:
return 1;
default:
System.out.println("Wrong option selected");
}
return 0;
}
}