|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--Direction
A Direction object represents a direction in 2-dimensional space. The angle of a direction may be obtained by using either the getDegrees() method or the getRadians() method. The angle is measured anti-clockwise from the East direction . For example, 0 degrees indicates a direction of East, 90 degrees indicates North,
A new Direction object may be created by specifying the degrees as a parameter to the constructor. In addition, common Directions have been defined as static members of this class. For example:
Direction.NORTHmay be used instead of
new Direction(90.0)
Field Summary | |
static Direction |
EAST
A predefined Direction representing East. |
static Direction |
NORTH
A predefined Direction representing North. |
static Direction |
NORTH_EAST
A predefined Direction representing Northeast. |
static Direction |
NORTH_WEST
A predefined Direction representing Northwest. |
static Direction |
SOUTH
A predefined Direction representing South. |
static Direction |
SOUTH_EAST
A predefined Direction representing Southeast. |
static Direction |
SOUTH_WEST
A predefined Direction representing Southwest. |
static Direction |
WEST
A predefined Direction representing West. |
Constructor Summary | |
Direction(double degrees)
Creates a new Direction object, specified in degrees. |
Method Summary | |
double |
getDegrees()
Gets the angle of this Direction in degrees. |
Direction |
getOppositeDirection()
Returns a new direction object that points in the opposite direction to this one. |
double |
getRadians()
Gets the angle of this Direction in radians. |
Direction |
getRelativeDirection(double degrees)
Gets a new direction relative to this direction by adding the number of degrees specified. |
String |
toString()
Returns all information about an instance of a Direction as a string. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final Direction EAST
public static final Direction NORTH
public static final Direction NORTH_EAST
public static final Direction NORTH_WEST
public static final Direction SOUTH
public static final Direction SOUTH_EAST
public static final Direction SOUTH_WEST
public static final Direction WEST
Constructor Detail |
public Direction(double degrees)
degrees
- the angle of this direction, specified in degrees.Method Detail |
public double getDegrees()
public Direction getOppositeDirection()
public double getRadians()
public Direction getRelativeDirection(double degrees)
Direction north = new Direction(90.0); Direction newDirection = north.getRelativeDirection(20.0);
newDirection.getDegrees()
should return 110.0
.
degrees
- specifies how many degrees should be added to produce
the new direction.
public String toString()
It can be very useful to have a "toString" method in any class you write. It allows you to use a reference to an object of that class as if that object is a string. For example, you can use the name of the object in some sort of an output, as if the object is a string, and the Java runtime environment will use your "toString" to produce a real String.
toString
in class Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |