|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||
java.lang.Object | +--Fish
Marine Biology Simulation: The Fish class 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.
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 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. |
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. |
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 for this fish. |
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 and
dir are valid for env.)env - environment in which fish will liveloc - location of the new fish in envdir - direction the new fish is facing
public Fish(Environment env,
Location loc,
Direction dir,
java.awt.Color col)
loc and
dir are valid for env.)env - environment in which fish will liveloc - location of the new fish in envdir - direction the new fish is facingcol - color of the new fish| Method Detail |
protected java.awt.Color randomColor()
public int id()
public Environment environment()
public java.awt.Color color()
public Location location()
location in interface Locatablepublic 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.Objectpublic void act()
protected 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 value
|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||