|
AP® Computer Science Marine Biology Simulation | |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--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). The choice of possible cardinal directions depends on the number of cardinal directions and the starting direction. |
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 |
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 testtrue
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 turnpublic Direction toLeft()
Direction
object.public Direction toLeft(int deg)
deg
degrees
to the left of this Direction
object.deg
- the number of degrees to turnpublic Direction reverse()
Direction
object.public java.lang.String toString()
toString
in class java.lang.Object
public Direction roundedDir(int numDirections, Direction startingDir)
numDirections
- the number of "cardinal" directionsstartingDir
- the starting cardinal directionpublic static Direction randomDirection()
|
AP® Computer Science Marine Biology Simulation | |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |