firs step forward sucessfully
This commit is contained in:
parent
f27d458b49
commit
3f4aafd43e
|
@ -1,8 +1,17 @@
|
||||||
package cat.hack3.codingtests.marsrover;
|
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 {
|
public class Coordinates {
|
||||||
private final int latitude;
|
private int latitude;
|
||||||
private final int longitude;
|
private int longitude;
|
||||||
|
|
||||||
public static Coordinates of(int latitude, int longitude) {
|
public static Coordinates of(int latitude, int longitude) {
|
||||||
return new Coordinates(latitude, longitude);
|
return new Coordinates(latitude, longitude);
|
||||||
|
@ -13,6 +22,11 @@ public class Coordinates {
|
||||||
this.longitude = longitude;
|
this.longitude = longitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Coordinates incrementSouth() {
|
||||||
|
latitude++;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
|
|
|
@ -2,16 +2,21 @@ package cat.hack3.codingtests.marsrover;
|
||||||
|
|
||||||
public class MarsRover {
|
public class MarsRover {
|
||||||
private final MarsMap marsMap;
|
private final MarsMap marsMap;
|
||||||
private final int latitudeStartingPoint;
|
private Coordinates currentCoordinates;
|
||||||
private final int longitudeStartingPoint;
|
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.marsMap = marsMap;
|
||||||
this.latitudeStartingPoint = latitudeStartingPoint;
|
currentCoordinates = startingCoordinates;
|
||||||
this.longitudeStartingPoint = longitudeStartingPoint;
|
currentDirection = startingDirection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Coordinates moveForward() {
|
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 latitudeStartingPoint = 2;
|
||||||
int longitudeStartingPoint = 3;
|
int longitudeStartingPoint = 3;
|
||||||
rover = new MarsRover(marsMap, latitudeStartingPoint, longitudeStartingPoint, SOUTH);
|
var startingCoordinates = Coordinates.of(latitudeStartingPoint, longitudeStartingPoint);
|
||||||
|
rover = new MarsRover(marsMap, startingCoordinates, SOUTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue