diff --git a/src/AutonomousCarController.java b/src/AutonomousCarController.java index 140b1be..614014c 100644 --- a/src/AutonomousCarController.java +++ b/src/AutonomousCarController.java @@ -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, @@ -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"); diff --git a/src/CarUI.java b/src/CarUI.java index eef76c8..13576c9 100644 --- a/src/CarUI.java +++ b/src/CarUI.java @@ -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: diff --git a/src/ManualStartStrategy.java b/src/ManualStartStrategy.java new file mode 100644 index 0000000..0723cc5 --- /dev/null +++ b/src/ManualStartStrategy.java @@ -0,0 +1,5 @@ +public class ManualStartStrategy implements StartStrategy { + public void start() { + System.out.println("Starting vehicle using manual input"); + } +} \ No newline at end of file diff --git a/src/ManualStopStrategy.java b/src/ManualStopStrategy.java new file mode 100644 index 0000000..3d5499c --- /dev/null +++ b/src/ManualStopStrategy.java @@ -0,0 +1,5 @@ +public class ManualStopStrategy implements StopStrategy { + public void stop() { + System.out.println("Stopping vehicle using manual input"); + } +} \ No newline at end of file diff --git a/src/RemoteStartStrategy.java b/src/RemoteStartStrategy.java new file mode 100644 index 0000000..6e53953 --- /dev/null +++ b/src/RemoteStartStrategy.java @@ -0,0 +1,5 @@ +public class RemoteStartStrategy implements StartStrategy { + public void start() { + System.out.println("Starting vehicle using remote input"); + } +} \ No newline at end of file diff --git a/src/RemoteStopStrategy.java b/src/RemoteStopStrategy.java new file mode 100644 index 0000000..e0a69df --- /dev/null +++ b/src/RemoteStopStrategy.java @@ -0,0 +1,5 @@ +public class RemoteStopStrategy implements StopStrategy { + public void stop() { + System.out.println("Stopping vehicle using remote input"); + } +} \ No newline at end of file diff --git a/src/StartStrategy.java b/src/StartStrategy.java new file mode 100644 index 0000000..5271c07 --- /dev/null +++ b/src/StartStrategy.java @@ -0,0 +1,3 @@ +public interface StartStrategy { + void start(); +} \ No newline at end of file diff --git a/src/StopStrategy.java b/src/StopStrategy.java new file mode 100644 index 0000000..1b425af --- /dev/null +++ b/src/StopStrategy.java @@ -0,0 +1,3 @@ +public interface StopStrategy { + void stop(); +} \ No newline at end of file diff --git a/src/TouchStartStrategy.java b/src/TouchStartStrategy.java new file mode 100644 index 0000000..16184ec --- /dev/null +++ b/src/TouchStartStrategy.java @@ -0,0 +1,5 @@ +public class TouchStartStrategy implements StartStrategy { + public void start() { + System.out.println("Starting vehicle using touch input"); + } +} \ No newline at end of file diff --git a/src/TouchStopStrategy.java b/src/TouchStopStrategy.java new file mode 100644 index 0000000..3a40dc1 --- /dev/null +++ b/src/TouchStopStrategy.java @@ -0,0 +1,5 @@ +public class TouchStopStrategy implements StopStrategy { + public void stop() { + System.out.println("Stopping vehicle using touch input"); + } +} \ No newline at end of file diff --git a/src/VoiceStartStrategy.java b/src/VoiceStartStrategy.java new file mode 100644 index 0000000..948d370 --- /dev/null +++ b/src/VoiceStartStrategy.java @@ -0,0 +1,5 @@ +public class VoiceStartStrategy implements StartStrategy { + public void start() { + System.out.println("Starting vehicle using voice input"); + } +} \ No newline at end of file diff --git a/src/VoiceStopStrategy.java b/src/VoiceStopStrategy.java new file mode 100644 index 0000000..3c88870 --- /dev/null +++ b/src/VoiceStopStrategy.java @@ -0,0 +1,5 @@ +public class VoiceStopStrategy implements StopStrategy { + public void stop() { + System.out.println("Stopping vehicle using voice input"); + } +} \ No newline at end of file