Class AquaFish

java.lang.Object
  extended by AquaFish

public class AquaFish
extends java.lang.Object

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

Created:
10 July 2002, Alyce Brady

Modifications:
22 March 2008, Alyce Brady, Simplified by removing references to AquaPoint and Direction classes and moving calculation of valid random starting locations to the Aquarium class.
23 March 2008, Alyce Brady, Modified to put some of the more complex methods in the NavigationAide class, to make the AquaFish class easier to read.
(date), (your name), Modified to ....

Version:
23 March 2008
Author:
(your name) (with assistance from)
See Also:
Aquarium

Field Summary
static int MAX_DISTANCE
           
static int MIN_DISTANCE
           
 
Constructor Summary
AquaFish(Aquarium aqua)
          The AquaFish constructor sets properties of the AquaFish.
 
Method Summary
 Aquarium aquarium()
          Gets the aquarium in which this fish moves.
 boolean atWall()
          Determine whether this fish is at a wall.
 void changeDir()
          Reverses direction.
 java.awt.Color color()
          Gets fish's color.
 boolean facingLeft()
          Determines whether this fish is facing left.
 boolean facingRight()
          Determines whether this fish is facing right.
 int height()
          Gets the height of this fish.
 int id()
          Gets the unique identifier for this fish.
 int length()
          Gets the length of this fish.
 void moveForward()
          Moves forward horizontally by random increments, staying within the aquarium.
 java.lang.String toString()
          This function is provided primarily for debugging purposes.
 int xCoord()
          Gets this fish's x coordinate in the aquarium.
 int yCoord()
          Gets this fish's y coordinate in the aquarium.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_DISTANCE

public static final int MAX_DISTANCE
See Also:
Constant Field Values

MIN_DISTANCE

public static final int MIN_DISTANCE
See Also:
Constant Field Values
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
Method Detail

aquarium

public Aquarium aquarium()
Gets the aquarium in which this fish moves.

Returns:
the aquarium in which this fish exists

atWall

public boolean atWall()
Determine whether this 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.


changeDir

public void changeDir()
Reverses direction.


color

public java.awt.Color color()
Gets fish's color.

Returns:
the color of this fish

facingLeft

public boolean facingLeft()
Determines whether this fish is facing left.

Returns:
true if fish is facing left; false otherwise

facingRight

public boolean facingRight()
Determines whether this fish is facing right.

Returns:
true if fish is facing right; false otherwise

height

public int height()
Gets the height of this fish.

Returns:
fish height

id

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

Returns:
the ID of the fish

length

public int length()
Gets the length of this fish.

Returns:
fish length

moveForward

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


toString

public java.lang.String toString()
This function is provided primarily for debugging purposes.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of a fish

xCoord

public int xCoord()
Gets this fish's x coordinate in the aquarium.

Returns:
the x coordinate in the aquarium of the fish's centerpoint

yCoord

public int yCoord()
Gets this fish's y coordinate in the aquarium.

Returns:
the y coordinate in the aquarium of the fish's centerpoint