Class Aquarium

java.lang.Object
  extended by Aquarium

public class Aquarium
extends java.lang.Object

Aquarium Lab Series:
The Aquarium class defines an Aquarium and its properties. An Aquarium object provides methods that report the aquarium's dimensions and that return random valid coordinates. These methods are useful for creating a new fish and for moving fish, to make sure that they are always fully within the aquarium. An Aquarium object also keeps track of the fish in the aquarium, with methods for adding a new fish or returning a list of all the fish. The latter method is used by the display to display all the fish when it displays the aquarium.

Created:
10 July 2002, Alyce Brady

Modifications:
22 March 2008, Alyce Brady, Added randomCenterX and randomCenterY methods, moving that logic from the old AquaFish class to the Aquarium class.
23 March 2008, Alyce Brady, Added list of fish to the aquarium to simplify the display of an aquarium containing fish.

Version:
23 March 2008
Author:
Alyce Brady

Constructor Summary
Aquarium(int width, int height)
          Constructs an Aquarium with user-specified size.
 
Method Summary
 void add(AquaFish fish)
          Adds the given fish to this aquarium.
 java.awt.Color color()
          Determines the color of the aquarium (water color).
 java.util.ArrayList<AquaFish> getFish()
          Returns a list of the fish in this aquarium.
 int height()
          Determines the height of the aquarium.
 int randomCenterX(int objectLength)
          Determines a valid random X coordinate along the x axis to be used for the centerpoint of an object with the given length.
 int randomCenterY(int objectHeight)
          Determines a valid random y coordinate along the y axis to be used for the centerpoint of an object with the given width or height.
 boolean validLoc(int xCoord, int yCoord)
          Determines whether the given coordinates specify a valid location (one that exists within the bounds of the aquarium).
 int width()
          Determines the width of the aquarium.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Aquarium

public Aquarium(int width,
                int height)
Constructs an Aquarium with user-specified size.

Parameters:
width - width of the aquarium when displayed (in pixels)
height - height of the aquarium when displayed (in pixels)
Method Detail

add

public void add(AquaFish fish)
Adds the given fish to this aquarium.

Parameters:
fish - the fish to add to this aquarium

color

public java.awt.Color color()
Determines the color of the aquarium (water color).

Returns:
the Color of the aquarium

getFish

public java.util.ArrayList<AquaFish> getFish()
Returns a list of the fish in this aquarium.

Returns:
list of fish in this aquarium

height

public int height()
Determines the height of the aquarium.

Returns:
the height of the aquarium

randomCenterX

public int randomCenterX(int objectLength)
Determines a valid random X coordinate along the x axis to be used for the centerpoint of an object with the given length. Precondition: this aquarium must be big enough to accomodate the object with the given length, plus 10 pixels of padding in each direction.

Parameters:
objectLength - length of object to be placed in aquarium
Returns:
a random X coordinate that could be used as a part of a valid centerpoint for an object of the given length in this aquarium

randomCenterY

public int randomCenterY(int objectHeight)
Determines a valid random y coordinate along the y axis to be used for the centerpoint of an object with the given width or height. Precondition: this aquarium must be big enough to accomodate the object with the given height, plus 10 pixels of padding above and below.

Parameters:
objectHeight - height of object to be placed in aquarium
Returns:
a random Y coordinate that could be used as a part of a valid centerpoint for an object of the given height in this aquarium

validLoc

public boolean validLoc(int xCoord,
                        int yCoord)
Determines whether the given coordinates specify a valid location (one that exists within the bounds of the aquarium).

Parameters:
xCoord - x coordinate of location to be checked
yCooord - y coordinate of location to be checked
Returns:
true if the specified location is within the bounds of the aquarium

width

public int width()
Determines the width of the aquarium.

Returns:
the width of the aquarium