CS111 Direction Contract


Instances of the Direction class represent one of the four compass points: north, east, south, west.

Constants

The following constant directions specify the four compass points:
public static final Direction NORTH
public static final Direction EAST
public static final Direction SOUTH
public static final Direction WEST

Instance Methods

public Direction left ()
Returns the compass point to the left of this direction.

public Direction right ()
Returns the compass point to the right of this direction.

public Direction opposite ()
Returns the compass point opposite to this direction.

public Point translate (int n, Point p)
Returns a new point that is the translation by n units of the given point p in this direction. For instance, if p1 represents the mathematical point (5,7), then the result of d.translate(3,p1) is (5,10) if d is NORTH, (8,7) if d is EAST, (5,4) if d is SOUTH, and (2,7) if d is WEST.

public boolean equals (Direction d)
Returns true if this direction equals d, and false otherwise. Direction is implemented in a way such that d1 == d2 and d1.equals(d2) always give the same result, but it would be an abstraction violation to rely on this.

public String toString ()
Returns a string representation of this direction.