firs step forward sucessfully
This commit is contained in:
parent
f27d458b49
commit
3f4aafd43e
|
@ -1,8 +1,17 @@
|
|||
package cat.hack3.codingtests.marsrover;
|
||||
|
||||
/**
|
||||
* Notice that the representation is the following:
|
||||
* Latitude is Y, starts from 0 on the top and goes down incrementally
|
||||
* Longitude is X, starts from 0 on the left and goes to right incrementally
|
||||
* 0 1 2 3
|
||||
* 1 11 12 13
|
||||
* 2 12 22 23
|
||||
* 3 13 23 33
|
||||
*/
|
||||
public class Coordinates {
|
||||
private final int latitude;
|
||||
private final int longitude;
|
||||
private int latitude;
|
||||
private int longitude;
|
||||
|
||||
public static Coordinates of(int latitude, int longitude) {
|
||||
return new Coordinates(latitude, longitude);
|
||||
|
@ -13,6 +22,11 @@ public class Coordinates {
|
|||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
public Coordinates incrementSouth() {
|
||||
latitude++;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
|
|
@ -2,16 +2,21 @@ package cat.hack3.codingtests.marsrover;
|
|||
|
||||
public class MarsRover {
|
||||
private final MarsMap marsMap;
|
||||
private final int latitudeStartingPoint;
|
||||
private final int longitudeStartingPoint;
|
||||
private Coordinates currentCoordinates;
|
||||
private MarsMap.Direction currentDirection;
|
||||
|
||||
public MarsRover(MarsMap marsMap, int latitudeStartingPoint, int longitudeStartingPoint, MarsMap.Direction startingDirection) {
|
||||
public MarsRover(MarsMap marsMap, Coordinates startingCoordinates, MarsMap.Direction startingDirection) {
|
||||
this.marsMap = marsMap;
|
||||
this.latitudeStartingPoint = latitudeStartingPoint;
|
||||
this.longitudeStartingPoint = longitudeStartingPoint;
|
||||
currentCoordinates = startingCoordinates;
|
||||
currentDirection = startingDirection;
|
||||
}
|
||||
|
||||
public Coordinates moveForward() {
|
||||
return Coordinates.of(0, 0);
|
||||
return switch (currentDirection) {
|
||||
case NORTH -> null;
|
||||
case SOUTH -> currentCoordinates.incrementSouth();
|
||||
case EAST -> null;
|
||||
case WEST -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,8 @@ public class MarsRoverTest {
|
|||
|
||||
int latitudeStartingPoint = 2;
|
||||
int longitudeStartingPoint = 3;
|
||||
rover = new MarsRover(marsMap, latitudeStartingPoint, longitudeStartingPoint, SOUTH);
|
||||
var startingCoordinates = Coordinates.of(latitudeStartingPoint, longitudeStartingPoint);
|
||||
rover = new MarsRover(marsMap, startingCoordinates, SOUTH);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue