|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--edu.kzoo.grid.Direction
AP® Computer Science Marine Biology Simulation:
The Direction
class encapsulates the notion of a compass
direction such as North, East, South, West.
The Direction
class is
copyright© 2002 College Entrance Examination Board
(www.collegeboard.com).
Field Summary | |
static Direction |
EAST
|
static int |
FULL_CIRCLE
Number of degrees in compass (will not be tested on the Advanced Placement exam). |
static Direction |
NORTH
|
static Direction |
NORTHEAST
|
static Direction |
NORTHWEST
|
static Direction |
SOUTH
|
static Direction |
SOUTHEAST
|
static Direction |
SOUTHWEST
|
static Direction |
WEST
|
Constructor Summary | |
Direction()
Constructs a default Direction object facing North. |
|
Direction(int degrees)
Constructs a Direction object. |
|
Direction(java.lang.String str)
Constructs a Direction object. |
Method Summary | |
boolean |
equals(java.lang.Object other)
Indicates whether some other Direction object
is "equal to" this one. |
int |
hashCode()
Generates a hash code for this direction (will not be tested on the Advanced Placement exam). |
int |
inDegrees()
Returns this direction value in degrees. |
static Direction |
randomDirection()
Returns a random direction. |
Direction |
reverse()
Returns the direction that is the reverse of this Direction object. |
Direction |
roundedDir(int numDirections,
Direction startingDir)
Rounds this direction to the nearest "cardinal" direction (will not be tested on the Advanced Placement exam). |
Direction |
toLeft()
Returns the direction that is a quarter turn to the left of this Direction object. |
Direction |
toLeft(int deg)
Returns the direction that is deg degrees
to the left of this Direction object. |
Direction |
toRight()
Returns the direction that is a quarter turn to the right of this Direction object. |
Direction |
toRight(int deg)
Returns the direction that is deg degrees
to the right of this Direction object. |
java.lang.String |
toString()
Represents this direction as a string. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final Direction NORTH
public static final Direction NORTHEAST
public static final Direction EAST
public static final Direction SOUTHEAST
public static final Direction SOUTH
public static final Direction SOUTHWEST
public static final Direction WEST
public static final Direction NORTHWEST
public static final int FULL_CIRCLE
Constructor Detail |
public Direction()
Direction
object facing North.
public Direction(int degrees)
Direction
object.
degrees
- initial compass direction in degreespublic Direction(java.lang.String str)
Direction
object.
str
- compass direction specified as a string, e.g. "North"
java.lang.IllegalArgumentException
- if string doesn't match a known direction nameMethod Detail |
public int inDegrees()
Direction
object in degreespublic boolean equals(java.lang.Object other)
Direction
object
is "equal to" this one.
equals
in class java.lang.Object
other
- the other position to test
true
if other
represents the same direction;
false
otherwisepublic int hashCode()
hashCode
in class java.lang.Object
Direction
objectpublic Direction toRight()
Direction
object.
public Direction toRight(int deg)
deg
degrees
to the right of this Direction
object.
deg
- the number of degrees to turn
public Direction toLeft()
Direction
object.
public Direction toLeft(int deg)
deg
degrees
to the left of this Direction
object.
deg
- the number of degrees to turn
public Direction reverse()
Direction
object.
public java.lang.String toString()
toString
in class java.lang.Object
public Direction roundedDir(int numDirections, Direction startingDir)
The choice of possible cardinal directions depends on the number of cardinal directions and the starting direction. For example, the two cardinal directions starting at NORTH are NORTH and SOUTH. The two cardinal directions starting at EAST are EAST and WEST. The four cardinal directions starting at NORTH are NORTH, EAST, SOUTH, and WEST. The four cardinal directions starting from NORTHEAST are NORTHEAST, SOUTHEAST, SOUTHWEST, and NORTHWEST. (Precondition: 0 < numDirections <= 360)
numDirections
- the number of "cardinal" directionsstartingDir
- the starting cardinal direction
public static Direction randomDirection()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |