/* Location.java */ /** * This class implements a Location, which is a Point * that also records the distance traveled to reach this Point. * Locations are immutable. */ public class Location { /** Creates a new location initialized to illegal values, i.e., the * point is (-1, -1) and the distance is -1. */ public Location() { // PART II (a) YOUR CODE GOES HERE } /** Creates a new location initialized to (pt, dist) */ public Location( Point pt, int dist ) { // PART II (b) YOUR CODE GOES HERE } /** * Returns a new Location (p, d) such that * 'p' == "this" point moved by one in the * direction 'dir', and the distance 'd' is * updated. */ public Location move( int dir ) { // PART II (c) REMOVE THE FOLLOWING LINE // AND INSERT YOUR CODE HERE return new Location(); } /** * Return the point in this location. */ Point getPoint() { return point; } /** * Return the distance in this location. */ int getDistance() { return distance; } /** * Return a string representation of the location. */ public String toString() { return "[" + point.toString() + ", " + distance + "]"; } // Data fields private Point point; // the location of the point private int distance; // the distance traveled to get here };