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