Class SimpleGrid

java.lang.Object
  extended by edu.kzoo.grid.Grid
      extended by edu.kzoo.grid.BoundedGrid
          extended by SimpleGrid

public class SimpleGrid
extends edu.kzoo.grid.BoundedGrid

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.

Version:
8 January 2009
Author:
Alyce Brady

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

SimpleGrid

public SimpleGrid(int numRows,
                  int numCols)
Constructs a new SimpleGrid object with the given number of rows and the given number of columns.

Parameters:
numRows - the number of rows to give this simple grid
numCols - the number of columns to give this simple grid
Method Detail

add

public void add(edu.kzoo.grid.GridObject obj,
                int row,
                int col)
Adds a new object to this grid at the specified (row, col) location. (Precondition: obj.grid() and obj.location() are both null; location (row, col) is a valid empty location in this grid.)

Parameters:
obj - the new object to be added
row - 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)
Throws:
java.lang.IllegalArgumentException - if the precondition is not met

objectAt

public edu.kzoo.grid.GridObject objectAt(int row,
                                         int col)
Returns the object at a specific (row, col) location in this grid.

Parameters:
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)
Returns:
the object at location (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.

remove

public void remove(int row,
                   int col)
Removes whatever object is at the specified location in this grid. If there is no object at the specified location, this method does nothing.

Parameters:
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)