Back to marketplace

Grid World

No description yet. This curated deck is ready for daily study.

Total cards: 20•Content version: v4•Public deck•Updated: 8/1/2026

Card preview (20)

#1
Front (Question)

Location class constructor:

Back (Answer)

public Location(int row, int col)

#2
Front (Question)

Location accessor methods:

Back (Answer)

public int getRow(); public int getCol();

#3
Front (Question)

Location objects are _______

Back (Answer)

immutable. Once created, a Location object CANNOT change.

#4
Front (Question)

Location implements ________ and provides a _________ method that compares locations first by ____ and then, if equal, by _____.

Back (Answer)

Comparable, compareTo, row, column. Location also overrides Object’s equals method in a manner consistent with compareTo.

#5
Front (Question)

Location’s toString method converts a ____ into a ____

Back (Answer)

location, string

#6
Front (Question)

The Location class defines eight public constants:

Back (Answer)

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;

#7
Front (Question)

Seven more constants represent turns, with right turns being ______ and left turns _____

Back (Answer)

positive, negative. public static final int AHEAD = 0;

#8
Front (Question)

Location’s getAdjacentLocation(int dir) method:

Back (Answer)

returns the location that is adjacent to this location in the compass direction dir. Locations that touch in a corner are considered adjacent.

#9
Front (Question)

Location’s getDirectionToward(Location other) method:

Back (Answer)

returns the compass direction (in degrees) from this location to other.

#10
Front (Question)

Grid int numRows() method:

Back (Answer)

returns the number of rows for a bounded grid; -1 for an unbounded grid

#11
Front (Question)

Grid int numCols() method:

Back (Answer)

returns the number of columns for a bounded grid; -1 for an unbounded grid

#12
Front (Question)

Grid boolean isValid(Location loc) method:

Back (Answer)

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

#13
Front (Question)

Grid E get(Location loc) method:

Back (Answer)

returns the object at loc (or null if loc is empty)

#14
Front (Question)

Grid E put(Location loc, E obj) method:

Back (Answer)

puts obj at loc and returns the object previously at loc (or null if loc was empty)

#15
Front (Question)

Grid E remove(Location loc) method:

Back (Answer)

Removes the object at loc and returns that object (or null if loc was empty)

#16
Front (Question)

Grid ArrayList getOccupiedLocations() method:

Back (Answer)

returns the list of all occupied locations in the grid

#17
Front (Question)

Grid ArrayList getValidAdjacentLocations(Location loc) method:

Back (Answer)

Returns a list of all valid locations adjacent to loc

#18
Front (Question)

Grid ArrayList getEmptyAdjacentLocations(Location loc) method:

Back (Answer)

returns a list of all valid empty locations adjacent to loc

#19
Front (Question)

Grid ArrayList getOccupiedAdjacentLocations(Location loc) method:

Back (Answer)

returns a list of all valid occupied locations adjacent to loc

#20
Front (Question)

Grid ArrayList getNeighbors(Location loc) method:

Back (Answer)

returns a list of all objects in the occupied locations adjacent to loc