diff --git a/user-interface-console/src/main/java/cat/hack3/codingtests/marsrover/ui/console/RoverCommandsPerformer.java b/user-interface-console/src/main/java/cat/hack3/codingtests/marsrover/ui/console/RoverCommandsPerformer.java index 9d5e8ba..9484dfd 100644 --- a/user-interface-console/src/main/java/cat/hack3/codingtests/marsrover/ui/console/RoverCommandsPerformer.java +++ b/user-interface-console/src/main/java/cat/hack3/codingtests/marsrover/ui/console/RoverCommandsPerformer.java @@ -37,14 +37,20 @@ public class RoverCommandsPerformer { do { output("Insert command (f = forward, b = backward, l = turn left, r = turn right, q = quit):"); nextCommand = reader.next(); - switch (nextCommand) { + var report = switch (nextCommand) { case "f" -> moveForwardCommand.execute(); case "b" -> moveBackwardsCommand.execute(); case "l" -> turnLeftCommand.execute(); case "r" -> turnRightCommand.execute(); - case "q" -> output("Disconnecting from Mars..."); - default -> output("unknown command"); - } + default -> null; + }; + if (report == null) { + if (nextCommand.equals("q")) + output("Disconnecting from Mars..."); + else + output("unknown command"); + } else + output(report.toString()); } while (isNotExitSignal(nextCommand)); } }