misplaced responsibility fix
This commit is contained in:
parent
1d15cd7254
commit
6906fec8a1
|
@ -1,6 +1,8 @@
|
|||
package cat.hack3.codingtests.marsrover;
|
||||
|
||||
|
||||
import cat.hack3.codingtests.marsrover.MarsMap.Direction;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
|
@ -26,9 +28,15 @@ public class Coordinates {
|
|||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
public Coordinates incrementSouth() {
|
||||
latitude++;
|
||||
logger.info("incremented South latitude, now is "+latitude);
|
||||
public Coordinates updatePositionTowards(Direction direction) {
|
||||
switch (direction) {
|
||||
case NORTH -> latitude--;
|
||||
case SOUTH -> latitude++;
|
||||
case WEST -> longitude--;
|
||||
case EAST -> longitude++;
|
||||
}
|
||||
logger.info(String.format("Updated coordinates towards %s, now is %d-%d",
|
||||
direction, latitude, longitude));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ package cat.hack3.codingtests.marsrover;
|
|||
|
||||
public class MarsRover {
|
||||
private final MarsMap marsMap;
|
||||
private Coordinates currentCoordinates;
|
||||
private final Coordinates currentCoordinates;
|
||||
private MarsMap.Direction currentDirection;
|
||||
|
||||
public MarsRover(MarsMap marsMap, Coordinates startingCoordinates, MarsMap.Direction startingDirection) {
|
||||
|
@ -12,12 +12,7 @@ public class MarsRover {
|
|||
}
|
||||
|
||||
public Coordinates moveForward() {
|
||||
return switch (currentDirection) {
|
||||
case NORTH -> null;
|
||||
case SOUTH -> currentCoordinates.incrementSouth();
|
||||
case EAST -> null;
|
||||
case WEST -> null;
|
||||
};
|
||||
return currentCoordinates.updatePositionTowards(currentDirection);
|
||||
}
|
||||
|
||||
public MarsMap.Direction turnLeft() {
|
||||
|
|
Loading…
Reference in New Issue