|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||
Marine Biology Simulation: Environment provides an interface for a two-dimensional, grid-like environment containing locatable objects. For example, it could be an environment of fish for a marine biology simulation.
Direction,
Locatable,
Location| Method Summary | |
void |
add(Locatable obj)
Adds a new object to this environment at the location it specifies. |
Locatable[] |
allObjects()
Returns all the objects in this environment. |
Direction |
getDirection(Location fromLoc,
Location toLoc)
Returns the direction from one location to another. |
Location |
getNeighbor(Location fromLoc,
Direction compassDir)
Returns the nearest neighbor of a location in the specified direction. |
boolean |
isEmpty(Location loc)
Determines whether a specific location in this environment is empty. |
boolean |
isValid(Direction dir)
Verifies whether a direction is valid in this environment. |
boolean |
isValid(Location loc)
Verifies whether a location is valid in this environment. |
java.util.ArrayList |
neighborsOf(Location ofLoc)
Returns the immediately adjacent neighbors of a specified location. |
int |
numCellSides()
Returns the number of sides around each cell (will not be tested on the Advanced Placement exam). |
int |
numCols()
Returns number of columns in this environment. |
int |
numObjects()
Returns the number of objects in this environment. |
int |
numRows()
Returns number of rows in this environment. |
Locatable |
objectAt(Location loc)
Returns the object at a specific location in this environment. |
Direction |
randomDirection()
Generates a valid random direction. |
void |
recordMove(Locatable obj,
Location oldLoc)
Updates this environment to reflect the fact that an object moved. |
void |
remove(Locatable obj)
Removes the object from this environment. |
int |
turningAngle()
Returns the turning angle for turning in this environment, (for example, 45, 60, 90, 120, 180) (will not be tested on the Advanced Placement exam). |
| Method Detail |
public int numRows()
public int numCols()
public int numCellSides()
public int turningAngle()
public boolean isValid(Location loc)
loc - location to checktrue if loc is valid;
false otherwisepublic boolean isValid(Direction dir)
dir - direction to checktrue if dir is valid;
false otherwisepublic Direction randomDirection()
public Location getNeighbor(Location fromLoc,
Direction compassDir)
fromLoc - starting location for searchcompassDir - direction in which to look for nearest neighborfromLoc in given direction
public Direction getDirection(Location fromLoc,
Location toLoc)
toLoc is not a "straight shot" from
fromLoc, then the direction will be rounded to a valid
direction in this environment.fromLoc - starting location for searchtoLoc - destination locationfromLoc to toLoc,
rounded if necessarypublic java.util.ArrayList neighborsOf(Location ofLoc)
ofLoc - location whose neighbors to getofLocpublic int numObjects()
public Locatable[] allObjects()
public boolean isEmpty(Location loc)
loc - the location to testtrue if loc is a
valid location in the context of this environment
and is empty; false otherwisepublic Locatable objectAt(Location loc)
loc - the location in which to lookloc;
null if loc is not in the environment
or is emptypublic void add(Locatable obj)
obj.location() is a valid empty location.)obj - the new object to be addedjava.lang.IllegalArgumentException - if the precondition is not metpublic void remove(Locatable obj)
obj is in this environment.)obj - the object to be removedjava.lang.IllegalArgumentException - if the precondition is not met
public void recordMove(Locatable obj,
Location oldLoc)
obj.location() is a valid location
and there is no other object there.
Postcondition: obj is at the appropriate location
(obj.location()), and either oldLoc is
equal to obj.location() (there was no movement) or
oldLoc is empty.obj - the object that movedoldLoc - the previous location of objjava.lang.IllegalArgumentException - if the precondition is not met
|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||