Class Ship

java.lang.Object
  |
  +--java.util.Observable
        |
        +--Ship

public class Ship
extends java.util.Observable
implements java.lang.Runnable

Definition of a Ship class with position, speed, course and name information.


Field Summary
static double DEFAULT_COURSE
          Default course.
static double DEFAULT_SPEED
          Default speed.
static double DEFAULT_X
          Default X position.
static double DEFAULT_Y
          Default Y position.
 
Constructor Summary
Ship()
          Construct with default position, course and speed.
Ship(double x, double y)
          Construct with explicit position.
Ship(double x, double y, double course)
          Construct with explicit position and course.
Ship(double x, double y, double course, double speed)
          Construct with explicit position, course and speed.
Ship(double x, double y, double course, double speed, java.lang.String name)
          Construct with explicit position, course, speed and name.
Ship(java.lang.String name)
          Construct with a name.
 
Method Summary
 double getCourse()
          Return the current course.
 CourseAndPosition getCourseAndPosition()
          Return the current course and position.
 java.lang.String getName()
          Return the current name.
 Position getPosition()
          Return the current position.
 double getSpeed()
          Return the current speed.
 java.io.PrintWriter getWriter()
          Get the writer to be used for reporting.
 void move()
          Move the ship according to its current speed and position.
 void report()
          Report the ship's position, course and speed.
 void run()
          An implementation of the Runnable interface, to enable a Ship to be run in an independent thread, if required.
 void setCourse(double newCourse)
          Set the ship's course.
 void setPosition(double x, double y)
          Set the ship's position.
 void setPosition(Position newPosition)
          Set the ship's position.
 void setSpeed(double newSpeed)
          Set the ship's speed.
 void setWriter(java.io.PrintWriter w)
          Set the writer to be used for reporting.
 
Methods inherited from class java.util.Observable
addObserver, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_X

public static final double DEFAULT_X
Default X position.

DEFAULT_Y

public static final double DEFAULT_Y
Default Y position.

DEFAULT_COURSE

public static final double DEFAULT_COURSE
Default course.

DEFAULT_SPEED

public static final double DEFAULT_SPEED
Default speed.
Constructor Detail

Ship

public Ship(double x,
            double y,
            double course,
            double speed,
            java.lang.String name)
Construct with explicit position, course, speed and name.

Ship

public Ship(double x,
            double y,
            double course,
            double speed)
Construct with explicit position, course and speed. The ship has no name.

Ship

public Ship(double x,
            double y,
            double course)
Construct with explicit position and course. The ship has no name.

Ship

public Ship(double x,
            double y)
Construct with explicit position. The ship has no name.

Ship

public Ship()
Construct with default position, course and speed. The ship has no name.

Ship

public Ship(java.lang.String name)
Construct with a name.
Method Detail

setPosition

public void setPosition(double x,
                        double y)
Set the ship's position.

setPosition

public void setPosition(Position newPosition)
Set the ship's position.

setSpeed

public void setSpeed(double newSpeed)
Set the ship's speed.
Parameters:
newSpeed - A positive or negative value.

setCourse

public void setCourse(double newCourse)
Set the ship's course.
Parameters:
newCourse - The course in degrees. Values are adjusted to the range [0..360)

report

public void report()
Report the ship's position, course and speed. Reporting is done via the ship's current.
See Also:
getWriter(), setWriter(PrintWriter)

move

public void move()
Move the ship according to its current speed and position.

run

public void run()
An implementation of the Runnable interface, to enable a Ship to be run in an independent thread, if required.
Specified by:
run in interface java.lang.Runnable
See Also:
Runnable

getPosition

public Position getPosition()
Return the current position.
See Also:
Position

getCourse

public double getCourse()
Return the current course.

getSpeed

public double getSpeed()
Return the current speed.

getName

public java.lang.String getName()
Return the current name.

getCourseAndPosition

public CourseAndPosition getCourseAndPosition()
Return the current course and position.
See Also:
CourseAndPosition

getWriter

public java.io.PrintWriter getWriter()
Get the writer to be used for reporting.
See Also:
report()

setWriter

public void setWriter(java.io.PrintWriter w)
Set the writer to be used for reporting.
See Also:
report()