|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.collegeboard.gridworld.grid.Location
public class Location
AP® Computer Science Marine Biology Simulation:
A Location
object represents the row and column of a
location in a two-dimensional grid.
The Location
class is
copyright© 2002 College Entrance Examination Board
(www.collegeboard.com).
Field Summary | |
---|---|
static int |
EAST
|
static int |
FULL_CIRCLE
|
static int |
HALF_CIRCLE
|
static int |
HALF_LEFT
|
static int |
HALF_RIGHT
|
static int |
LEFT
|
static int |
NORTH
|
static int |
NORTHEAST
|
static int |
NORTHWEST
|
static int |
RIGHT
|
static int |
SOUTH
|
static int |
SOUTHEAST
|
static int |
SOUTHWEST
|
static int |
WEST
|
Constructor Summary | |
---|---|
Location(int row,
int col)
Constructs a Location object. |
Method Summary | |
---|---|
int |
col()
Returns the column coordinate of this location. |
int |
compareTo(Object other)
Compares this location to other for ordering. |
int |
directionToward(Location target)
Returns the direction from this location toward another location |
boolean |
equals(Object other)
Indicates whether some other Location object is
"equal to" this one. |
Location |
getNeighborLocation(int direction)
Gets the neighbor location in the given direction |
int |
hashCode()
Generates a hash code for this location (will not be tested on the Advanced Placement exam). |
int |
row()
Returns the row coordinate of this location. |
String |
toString()
Represents this location as a string. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int FULL_CIRCLE
public static final int HALF_CIRCLE
public static final int HALF_LEFT
public static final int LEFT
public static final int HALF_RIGHT
public static final int RIGHT
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 row, int col)
Location
object.
row
- location's rowcol
- location's columnMethod Detail |
---|
public int row()
public int col()
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 at the
same row and column as the current location;
false
otherwisepublic int hashCode()
hashCode
in class Object
Location
objectpublic int compareTo(Object 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.
(Precondition: other
is a Location
object.)
compareTo
in interface Comparable
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
public Location getNeighborLocation(int direction)
direction
- an angle (0 degrees = Location.NORTH,
45 degrees = Location.NORTHWEST, etc.)
public int directionToward(Location target)
target
- another location
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |