/**
 * A rectangular array of objects
 *
 */
public class RectangularArray
{
    private int       columns, rows;
    private Object[]  data;
    

    /**
     * Explicit Value Constructor
     *
     * @param rows    The number of rows
     * @param columbs The number of columns
     */
    public RectangularArray(int rows, int columns)
    {
      this.columns = columns;
		this.rows    = rows;
    }// end RectangularArray constructor


    /**
     * Returns the number of columns in this RectangularArray
     *
     * @return   The number of columns
     */
    public int columns()
    {
       return columns;  
    } // end columns
    
    /**
     * Get the element at a particular row and column
     *
     * @param row     The row index
     * @param column  The column index
     * @return        The Object at the given row and column
     */
    public Object getElementAt(int row, int column)
	 								throws IndexOutOfBoundsException
    {
        Object myObject;
		  int i;
		  i = index(row, column);
		  //if (i >= 0)
		   myObject = data[i];
		  //else
		  //    myObject = null;
			return myObject;
    }// end getElementAt
    
    /**
     * This implementation uses an ordinary array as the underlying
     * data structure.  This converts from VALID row and column indexes
     * to an index into the underlying data structure.
     *
     * @param row     The row index
     * @param column  The column index
     * @return        The corresponding index in the data array
     */
    private int index(int row, int column) 
                   //  throws IndexOutOfBoundsException
    {
	     int i;
		  i = row*column + column;         
        if (row > rows || columns > columns || i > data.length)
		     throw new IndexOutOfBoundsException 
			  (" row: " + row + " column: " + column);
		  else
		     return i;
    }// end index
    

    /**
     * Returns the number of rows in this RectangularArray
     *
     * @return   The number of rows
     */
    public int rows()
    {
       return rows;
    } // end rows
    
  
    /**
     * Set the element at a particular row and column
     *
     * @param row     The row index
     * @param column  The column index
     * @param o       The Object to put in the array
     */
    public void setElementAt(int row, int column, Object o)
									 throws IndexOutOfBoundsException
    {
          int location;
	       location = index(row,column);
		  //  if (location >= 0)
			    data[location] = o;   // terrible variable name
		    
    } // end setElementAt
}// end class
