Aquarium Lab Series

Partial Specification for Class AquaFish

java.lang.Object
  |
  +--AquaFish

public class AquaFish
extends java.lang.Object

Aquarium Lab Series: The AquaFish class defines a fish in an aquarium.

Version:
10 July 2002
See Also:
Aquarium, AquaPoint

Constructor Summary
AquaFish(Aquarium aqua)
          The AquaFish constructor sets properties of the AquaFish.
AquaFish(Aquarium aqua, java.awt.Color color)
          The AquaFish constructor sets properties of the AquaFish.
 
Method Summary
 boolean atWall()
          Determine whether the fish is at a wall.
 void changeDir()
          Reverse direction.
 java.awt.Color color()
          Get fish's color.
 int id()
          Get the unique identifier for this fish.
 void moveForward()
          Move forward horizontally by random increments, staying within the aquarium.
 AquaPoint position()
          Get the fish's position in the aquarium.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AquaFish

public AquaFish(Aquarium aqua)
The AquaFish constructor sets properties of the AquaFish. Precondition: the aquarium must be big enough to accommodate the biggest fish (currently 75 pixels long and 30 pixels high) plus 10 pixels of padding in all four directions.
Parameters:
aqua - the Aquarium in which to place the fish

AquaFish

public AquaFish(Aquarium aqua,
                java.awt.Color color)
The AquaFish constructor sets properties of the AquaFish. This version of the constructor allows the user to select the Color to be associated with the fish. Precondition: the aquarium must be big enough to accomodate the biggest fish (currently 75 pixels long and 30 pixels high) plus 10 pixels of padding in all four directions.
Parameters:
aqua - the Aquarium in which to place the fish
color - the Color to associate with the fish
Method Detail

id

public int id()
Get the unique identifier for this fish.

color

public java.awt.Color color()
Get fish's color.
Returns:
the color of this fish

position

public AquaPoint position()
Get the fish's position in the aquarium.

atWall

public boolean atWall()
Determine whether the fish is at a wall. A fish is considered at a wall if it cannot move forward; in other words, if the distance from the fish to the wall it faces is less than the minimum distance that a fish can move forward.

moveForward

public void moveForward()
Move forward horizontally by random increments, staying within the aquarium.

changeDir

public void changeDir()
Reverse direction.

Aquarium Lab Series

Copyright© 2002 Alyce Brady