|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object ants.AntWorld
public class AntWorld
The model for the ant simulation
Contains the field (2-D array) in which Ants and DoodleBugs live
Class Invariant: Nr of rows and columns in the gird are positive and do not change once initialized
Constructor Summary | |
---|---|
AntWorld(int nrAnts,
int nrBugs)
Construct an AntWorld with a size x size 2-D array containing nrAnts and nrBugs. |
Method Summary | |
---|---|
Critter |
getAt(int row,
int column)
Accessor for a cell in the field; required by AntGUI |
int |
getStepNr()
Accessor for step number; required by AntGUI |
void |
simulateOneStep()
Execute one time step of the simulation; called from AntGUI |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AntWorld(int nrAnts, int nrBugs)
Preconditions: (Guaranteed by the GUI)
1. nrAnts and nrBugs are not negative
2. The total number of ants + bugs does not exceed the number of cells in the 2-D array (rows * columns).
PostCondition: Critter array is created and populated; instance variables initialized
nrAnts
- - the initial number of AntsnrBugs
- - the initial number of DoodleBugsMethod Detail |
---|
public int getStepNr()
public Critter getAt(int row, int column)
Precondition: the row and column are valid for the field
row
- - the row coordinate of the cell to be accessedcolumn
- - the column coordinate of the row to be accessed
public void simulateOneStep()
Precondition: the world has been initialized
Postcondition: Executes one step of the simulation by
a. Moving all the critters
b. Adding new critters (breeding)
c. Removing critters that have starved
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |