java.lang.ObjectAquarium
public class Aquarium
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.
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 |
---|
public Aquarium(int width, int height)
width
- width of the aquarium when displayed (in pixels)height
- height of the aquarium when displayed (in pixels)Method Detail |
---|
public void add(AquaFish fish)
fish
- the fish to add to this aquariumpublic java.awt.Color color()
public java.util.ArrayList<AquaFish> getFish()
public int height()
public int randomCenterX(int objectLength)
objectLength
- length of object to be placed in aquarium
public int randomCenterY(int objectHeight)
objectHeight
- height of object to be placed in aquarium
public boolean validLoc(int xCoord, int yCoord)
xCoord
- x coordinate of location to be checkedyCooord
- y coordinate of location to be checked
public int width()