/**
 * 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;
		  data = new Object[rows*columns];
    }

    /**
     * Returns the number of columns in this RectangularArray
     *
     * @return   The number of columns
     */
    public int columns()
    {
       return this.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
    {
	       int temp;
	       temp = index(row,column);
          return data[temp];
    }

    /**
     * This implementation uses an ordinary array as the underlying
     * data structure.  This converts from 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
    {
        return  (this.columns)* row + column;
    }

    /**
     * Returns the number of rows in this RectangularArray
     *
     * @return   The number of rows
     */
    public int rows()
    {
         return this.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 temp;
		  temp = index(row, column);
        data[temp] = o;
    }
}