|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.Observable | +--Ship
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 |
public static final double DEFAULT_X
public static final double DEFAULT_Y
public static final double DEFAULT_COURSE
public static final double DEFAULT_SPEED
Constructor Detail |
public Ship(double x, double y, double course, double speed, java.lang.String name)
public Ship(double x, double y, double course, double speed)
public Ship(double x, double y, double course)
public Ship(double x, double y)
public Ship()
public Ship(java.lang.String name)
Method Detail |
public void setPosition(double x, double y)
public void setPosition(Position newPosition)
public void setSpeed(double newSpeed)
newSpeed
- A positive or negative value.public void setCourse(double newCourse)
newCourse
- The course in degrees. Values are
adjusted to the range [0..360)public void report()
getWriter()
,
setWriter(PrintWriter)
public void move()
public void run()
Runnable
public Position getPosition()
Position
public double getCourse()
public double getSpeed()
public java.lang.String getName()
public CourseAndPosition getCourseAndPosition()
CourseAndPosition
public java.io.PrintWriter getWriter()
report()
public void setWriter(java.io.PrintWriter w)
report()
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |