1
0
Fork 0

log also the rotation

This commit is contained in:
Xavier Fontanet 2024-06-21 13:37:33 +02:00
parent adbca95241
commit 530cf22983
1 changed files with 16 additions and 2 deletions

View File

@ -1,6 +1,11 @@
package cat.hack3.codingtests.marsrover;
import java.util.logging.Logger;
public class MarsRover {
Logger logger = Logger.getLogger(this.getClass().getName());
private enum Rotation {LEFT, RIGHT}
private final MarsMap marsMap;
private Direction currentDirection;
@ -18,11 +23,20 @@ public class MarsRover {
}
public Direction turnLeft() {
return currentDirection = currentDirection.getNextDirectionRotatingToLeft();
currentDirection = currentDirection.getNextDirectionRotatingToLeft();
reportNewDirection(Rotation.LEFT);
return currentDirection;
}
public Direction turnRight() {
return currentDirection = currentDirection.getNextDirectionRotatingToRight();
currentDirection = currentDirection.getNextDirectionRotatingToRight();
reportNewDirection(Rotation.RIGHT);
return currentDirection;
}
private void reportNewDirection(Rotation rotation) {
logger.info(String.format("Rotated towards %s, now the direction is %s",
rotation, currentDirection));
}
public Coordinates getCurrentCoordinates() {