Grid World Flashcards
Location class constructor:
public Location(int row, int col)
Location accessor methods:
public int getRow();
public int getCol();
Location objects are _______
immutable. Once created, a Location object CANNOT change.
Location implements ________ and provides a _________ method that compares locations first by ____ and then, if equal, by _____.
Comparable, compareTo, row, column. Location also overrides Object’s equals method in a manner consistent with compareTo.
Location’s toString method converts a ____ into a ____
location, string
The Location class defines eight public constants:
public static final int NORTH = 0; public static final int NORTHEAST = 45; public static final int EAST = 90; public static final int SOUTHEAST = 135; public static final int SOUTH = 180; public static final int SOUTHWEST = 225; public static final int WEST = 270; public static final int NORTHWEST = 315;
Seven more constants represent turns, with right turns being ______ and left turns _____
positive, negative.
public static final int AHEAD = 0;
Location’s getAdjacentLocation(int dir) method:
returns the location that is adjacent to this location in the compass direction dir. Locations that touch in a corner are considered adjacent.
Location’s getDirectionToward(Location other) method:
returns the compass direction (in degrees) from this location to other.
Grid int numRows() method:
returns the number of rows for a bounded grid; -1 for an unbounded grid
Grid int numCols() method:
returns the number of columns for a bounded grid; -1 for an unbounded grid
Grid boolean isValid(Location loc) method:
returns true if loc is valid in this grid (always true for an unbounded grid). DOES NOT tell whether or not the space is occupied
Grid E get(Location loc) method:
returns the object at loc (or null if loc is empty)
Grid E put(Location loc, E obj) method:
puts obj at loc and returns the object previously at loc (or null if loc was empty)
Grid E remove(Location loc) method:
Removes the object at loc and returns that object (or null if loc was empty)