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. A fish of this class can move in the aquarium (always staying fully within the aquarium), and can report its color, dimensions, and location, for the purpose of the display.

Created:
10 July 2002, Alyce Brady

Modifications:
2008-2009, Alyce Brady, Simplified by replacing two classes (AquaPoint and Direction) with single NavigationAide class.
(date), (your name), Modified to ....

Version:
18 January 2009
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.
AquaFish(Aquarium aqua, java.awt.Color newColor)
          The AquaFish constructor sets properties of the AquaFish.
 
Method Summary
 Aquarium aquarium()
          Gets the aquarium in which this fish lives.
 boolean atWall()
          Determine whether this fish is at a wall.
 void changeDir()
          Reverses direction.
 java.awt.Color color()
          Gets fish's color.
 int height()
          Gets the height of this fish.
 int id()
          Gets the unique identifier for this fish.
 boolean isFacingLeft()
          Determines whether this fish is facing left.
 boolean isFacingRight()
          Determines whether this fish is facing right.
 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. This constructor creates a white fish. 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 the fish will live

AquaFish

public AquaFish(Aquarium aqua,
                java.awt.Color newColor)
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 the fish will live
newColor - the color for the new fish
Method Detail

aquarium

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

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

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

isFacingLeft

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

Returns:
true if fish is facing left; false otherwise

isFacingRight

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

Returns:
true if fish is facing right; false otherwise

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