|
AP® Computer Science Marine Biology Simulation | |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--Fish
AP® Computer Science Marine Biology Simulation:
A Fish
object represents a fish in the Marine Biology
Simulation. Each fish has a unique ID, which remains constant
throughout its life. A fish also maintains information about its
location and direction in the environment.
Modification History: - Modified to support a dynamic population in the environment: fish can now breed and die.
The Fish
class is
copyright© 2002 College Entrance Examination Board
(www.collegeboard.com).
Environment
,
Direction
,
Location
Constructor Summary | |
Fish(Environment env,
Location loc)
Constructs a fish at the specified location in a given environment. |
|
Fish(Environment env,
Location loc,
Direction dir)
Constructs a fish at the specified location and direction in a given environment. |
|
Fish(Environment env,
Location loc,
Direction dir,
java.awt.Color col)
Constructs a fish of the specified color at the specified location and direction. |
Method Summary | |
void |
act()
Acts for one step in the simulation. |
protected boolean |
breed()
Attempts to breed into neighboring locations. |
protected void |
changeDirection(Direction newDir)
Modifies this fish's direction. |
protected void |
changeLocation(Location newLoc)
Modifies this fish's location and notifies the environment. |
java.awt.Color |
color()
Returns this fish's color. |
protected void |
die()
Removes this fish from the environment. |
Direction |
direction()
Returns this fish's direction. |
protected java.util.ArrayList |
emptyNeighbors()
Finds empty locations adjacent to this fish. |
Environment |
environment()
Returns this fish's environment. |
protected void |
generateChild(Location loc)
Creates a new fish with the color of its parent. |
int |
id()
Returns this fish's ID. |
boolean |
isInEnv()
Checks whether this fish is in an environment. |
Location |
location()
Returns this fish's location. |
protected void |
move()
Moves this fish in its environment. |
protected Location |
nextLocation()
Finds this fish's next location. |
protected java.awt.Color |
randomColor()
Generates a random color. |
java.lang.String |
toString()
Returns a string representing key information about this fish. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public Fish(Environment env, Location loc)
loc
is valid
for env
.)env
- environment in which fish will liveloc
- location of the new fish in env
public Fish(Environment env, Location loc, Direction dir)
loc
is valid
for env
.)env
- environment in which fish will liveloc
- location of the new fish in env
dir
- direction the new fish is facingpublic Fish(Environment env, Location loc, Direction dir, java.awt.Color col)
loc
is valid
for env
.)env
- environment in which fish will liveloc
- location of the new fish in env
dir
- direction the new fish is facingcol
- color of the new fishMethod Detail |
protected java.awt.Color randomColor()
public int id()
public Environment environment()
public java.awt.Color color()
public Location location()
location
in interface Locatable
public Direction direction()
public boolean isInEnv()
true
if the fish is in the environment
(and at the correct location); false
otherwisepublic java.lang.String toString()
toString
in class java.lang.Object
public void act()
protected boolean breed()
true
if fish successfully breeds;
false
otherwiseprotected void generateChild(Location loc)
loc
- location of the new fishprotected void move()
protected Location nextLocation()
nextLocation
returns its current location.protected java.util.ArrayList emptyNeighbors()
protected void changeLocation(Location newLoc)
newLoc
- new location valueprotected void changeDirection(Direction newDir)
newDir
- new direction valueprotected void die()
|
AP® Computer Science Marine Biology Simulation | |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |