/* * Class for representing a position in the range. */ class Position { private int x, y; public Position(int x, int y) { // constructor: set values for x and y this.x = x; this.y = y; } public int getX() { return x; } public int getY() { return y; } public String toString() { // format with the standard (x, y) pair notation return String.format("(%d, %d)", x, y); } public boolean equals(Position other) { // a useful equals method return this.x==other.x && this.y==other.y; } public Position move(Direction d) { // return the position that would result if we moved one // step in the given direction. Return a null reference if // that's not possible. if ( d == Direction.stay ) { return new Position(x, y); } else if ( d == Direction.east && x0 ) { return new Position(x-1, y); } else if ( d == Direction.north && y0 ) { return new Position(x, y-1); } return null; } }