|
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
|
+--SquareEnvironment
|
+--UnboundedEnv
AP® Computer Science Marine Biology Simulation:
The UnboundedEnv class models an unbounded, two-dimensional,
grid-like environment containing locatable objects. For example, it
could be an environment of fish for a marine biology simulation.
Modification History:
- Created to support multiple environment representations:
this class represents a second implementation of the
Environment interface.
The UnboundedEnv class is
copyright© 2002 College Entrance Examination Board
(www.collegeboard.com).
Locatable,
Location| Constructor Summary | |
UnboundedEnv()
Constructs an empty UnboundedEnv object. |
|
| 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. |
protected int |
indexOf(Location loc)
Get the index of the object at the specified location. |
boolean |
isEmpty(Location loc)
Determines whether a specific location in this environment is empty. |
boolean |
isValid(Location loc)
Verifies whether a location is valid in this environment. |
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. |
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. |
java.lang.String |
toString()
Creates a single string representing all the objects in this environment (not necessarily in any particular order). |
| Methods inherited from class SquareEnvironment |
getDirection, getNeighbor, neighborsOf, numAdjacentNeighbors, numCellSides, randomDirection |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public UnboundedEnv()
| Method Detail |
public int numRows()
public int numCols()
public boolean isValid(Location loc)
loc - location to checktrue if loc is valid;
false otherwisepublic 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 emptypublic java.lang.String toString()
toString in class java.lang.Objectpublic 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 metprotected int indexOf(Location loc)
loc - the location in which to lookloc
if there is one; -1 otherwise
|
AP® Computer Science Marine Biology Simulation | |||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||