log also the rotation
This commit is contained in:
parent
adbca95241
commit
530cf22983
|
@ -1,6 +1,11 @@
|
||||||
package cat.hack3.codingtests.marsrover;
|
package cat.hack3.codingtests.marsrover;
|
||||||
|
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class MarsRover {
|
public class MarsRover {
|
||||||
|
Logger logger = Logger.getLogger(this.getClass().getName());
|
||||||
|
private enum Rotation {LEFT, RIGHT}
|
||||||
|
|
||||||
private final MarsMap marsMap;
|
private final MarsMap marsMap;
|
||||||
private Direction currentDirection;
|
private Direction currentDirection;
|
||||||
|
|
||||||
|
@ -18,11 +23,20 @@ public class MarsRover {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Direction turnLeft() {
|
public Direction turnLeft() {
|
||||||
return currentDirection = currentDirection.getNextDirectionRotatingToLeft();
|
currentDirection = currentDirection.getNextDirectionRotatingToLeft();
|
||||||
|
reportNewDirection(Rotation.LEFT);
|
||||||
|
return currentDirection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Direction turnRight() {
|
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() {
|
public Coordinates getCurrentCoordinates() {
|
||||||
|
|
Loading…
Reference in New Issue