java.lang.Objectedu.kzoo.grid.Grid
edu.kzoo.grid.BoundedGrid
SimpleGrid
public class SimpleGrid
Simple Grid Object Programming Project:
A SimpleGrid object represents a simple bounded grid. In addition
to the methods it inherits from Grid and BoundedGrid, it provides
methods that take row and column parameters rather than Location
object parameters.
| Constructor Summary | |
|---|---|
SimpleGrid(int numRows,
int numCols)
Constructs a new SimpleGrid object with the given number of rows and the given number of columns. |
|
| Method Summary | |
|---|---|
void |
add(edu.kzoo.grid.GridObject obj,
int row,
int col)
Adds a new object to this grid at the specified (row, col) location. |
edu.kzoo.grid.GridObject |
objectAt(int row,
int col)
Returns the object at a specific (row, col) location in this grid. |
void |
remove(int row,
int col)
Removes whatever object is at the specified location in this grid. |
| Constructor Detail |
|---|
public SimpleGrid(int numRows,
int numCols)
numRows - the number of rows to give this simple gridnumCols - the number of columns to give this simple grid| Method Detail |
|---|
public void add(edu.kzoo.grid.GridObject obj,
int row,
int col)
obj.grid() and
obj.location() are both null; location
(row, col) is a valid empty location in this grid.)
obj - the new object to be addedrow - the row in which to place obj
(row numbering starts at 0)col - the column in which to place obj
(column numbering starts at 0)
java.lang.IllegalArgumentException - if the precondition is not met
public edu.kzoo.grid.GridObject objectAt(int row,
int col)
row - the row in which to look (where the first row is 0)col - the column in which to look (where the first column is 0)
(row, col);
null if (row, col) is not in
the grid or is empty. For example, the call
objectAt(0, 0) returns the object in the
upper-left corner (first row, first column), if there
is one, otherwise it returns null.
public void remove(int row,
int col)
row - the row location from which to remove an object
(row numbering starts at 0)col - the column location from which to remove an object
(column numbering starts at 0)