Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/AutonomousCarController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ public class AutonomousCarController {
private SurroundSensingSystemInterface surroundSensingSystemInterface;
private RoadSignReadingSystem roadSignReadingSystem;

private StartStrategy startStrategy;
private StopStrategy stopStrategy;


public void setDependencies(NavigationSystemInterface navigationSystemInterface,
AutoSystemInterface autoSystemInterface,
Expand All @@ -30,6 +33,32 @@ public void stop() {
System.out.println("Destination reached, stopping the car");
}

public void startVehicle() {
if (startStrategy != null) {
startStrategy.start();
}
else {
System.out.println("No start strategy set");
}
}

public void stopVehicle() {
if (stopStrategy != null) {
stopStrategy.stop();
}
else {
System.out.println("No stop strategy set");
}
}

public void setStartStrategy(StartStrategy strategy) {
this.startStrategy = strategy;
}

public void setStopStrategy(StopStrategy strategy) {
this.stopStrategy = strategy;
}

public void turnLeft(Double afterDistance) {
System.out.println("Checking signal, surroundings and road signs");

Expand Down
56 changes: 55 additions & 1 deletion src/CarUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,64 @@ public Integer readOption() {
break;

case 2:
autonomousCarController.start();
//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:
Expand Down
5 changes: 5 additions & 0 deletions src/ManualStartStrategy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class ManualStartStrategy implements StartStrategy {
public void start() {
System.out.println("Starting vehicle using manual input");
}
}
5 changes: 5 additions & 0 deletions src/ManualStopStrategy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class ManualStopStrategy implements StopStrategy {
public void stop() {
System.out.println("Stopping vehicle using manual input");
}
}
5 changes: 5 additions & 0 deletions src/RemoteStartStrategy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class RemoteStartStrategy implements StartStrategy {
public void start() {
System.out.println("Starting vehicle using remote input");
}
}
5 changes: 5 additions & 0 deletions src/RemoteStopStrategy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class RemoteStopStrategy implements StopStrategy {
public void stop() {
System.out.println("Stopping vehicle using remote input");
}
}
3 changes: 3 additions & 0 deletions src/StartStrategy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public interface StartStrategy {
void start();
}
3 changes: 3 additions & 0 deletions src/StopStrategy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public interface StopStrategy {
void stop();
}
5 changes: 5 additions & 0 deletions src/TouchStartStrategy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class TouchStartStrategy implements StartStrategy {
public void start() {
System.out.println("Starting vehicle using touch input");
}
}
5 changes: 5 additions & 0 deletions src/TouchStopStrategy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class TouchStopStrategy implements StopStrategy {
public void stop() {
System.out.println("Stopping vehicle using touch input");
}
}
5 changes: 5 additions & 0 deletions src/VoiceStartStrategy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class VoiceStartStrategy implements StartStrategy {
public void start() {
System.out.println("Starting vehicle using voice input");
}
}
5 changes: 5 additions & 0 deletions src/VoiceStopStrategy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class VoiceStopStrategy implements StopStrategy {
public void stop() {
System.out.println("Stopping vehicle using voice input");
}
}