|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object WatorWorld.Location
public class Location
A Location
object represents the row and column of a location
in a two-dimensional grid.
The API of this class is testable on the AP CS A and AB exams.
Field Summary | |
---|---|
static int |
AHEAD
The turn angle for making no turn. |
static int |
EAST
The compass direction for east. |
static int |
FULL_CIRCLE
The turn angle for turning a full circle. |
static int |
HALF_CIRCLE
The turn angle for turning a half circle. |
static int |
HALF_LEFT
The turn angle for turning 45 degrees to the left. |
static int |
HALF_RIGHT
The turn angle for turning 45 degrees to the right. |
static int |
LEFT
The turn angle for turning 90 degrees to the left. |
static int |
NORTH
The compass direction for north. |
static int |
NORTHEAST
The compass direction for northeast. |
static int |
NORTHWEST
The compass direction for northwest. |
static int |
RIGHT
The turn angle for turning 90 degrees to the right. |
static int |
SOUTH
The compass direction for south. |
static int |
SOUTHEAST
The compass direction for southeast. |
static int |
SOUTHWEST
The compass direction for southwest. |
static int |
WEST
The compass direction for west. |
Constructor Summary | |
---|---|
Location(int r,
int c)
Constructs a location with given row and column coordinates. |
Method Summary | |
---|---|
int |
compareTo(Location other)
Compares this location to other for ordering. |
boolean |
equals(Object other)
Indicates whether some other Location object is "equal to"
this one. |
Location |
getAdjacentLocation(int direction)
Gets the adjacent location in any one of the eight compass directions. |
int |
getCol()
Gets the column coordinate. |
int |
getDirectionToward(Location target)
Returns the direction from this location toward another location. |
int |
getRow()
Gets the row coordinate. |
int |
hashCode()
Generates a hash code. |
String |
toString()
Creates a string that describes this location. |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int LEFT
public static final int RIGHT
public static final int HALF_LEFT
public static final int HALF_RIGHT
public static final int FULL_CIRCLE
public static final int HALF_CIRCLE
public static final int AHEAD
public static final int NORTH
public static final int NORTHEAST
public static final int EAST
public static final int SOUTHEAST
public static final int SOUTH
public static final int SOUTHWEST
public static final int WEST
public static final int NORTHWEST
Constructor Detail |
---|
public Location(int r, int c)
r
- the rowc
- the columnMethod Detail |
---|
public int getRow()
public int getCol()
public Location getAdjacentLocation(int direction)
direction
- the direction in which to find a neighbor location
public int getDirectionToward(Location target)
target
- a location that is different from this location
target
public boolean equals(Object other)
Location
object is "equal to"
this one.
equals
in class Object
other
- the other location to test
true
if other
is a
Location
with the same row and column as this location;
false
otherwisepublic int hashCode()
hashCode
in class Object
public int compareTo(Location other)
other
for ordering. Returns a
negative integer, zero, or a positive integer as this location is less
than, equal to, or greater than other
. Locations are
ordered in row-major order. other
is a Location
object.)
compareTo
in interface Comparable<Location>
other
- the other location to test
other
, zero if the two locations are equal, or a positive
integer if this location is greater than other
public String toString()
toString
in class Object
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |