/**
 * This Driver class tests the RectangularArray
 * object.  RectangularArray stores a 2d array
 * in a one dimensional array.  This class
 * will ensure that it works properly.
 *
 * @author Kristopher Kalish
 * @version 1 - April 18th, 2007
 * 
 * Lab26
 * Section 1 
 * 
 ************************************************/
 /*
  *  References and Acknowledgements: I have recieved
  *  no unauthorized help on this assignment.
  */
  
import java.text.Format;

public class Driver
{
	public static void main(String args[])
	{
		// lets create and test an array
		// we must specify the type String
		RectangularArrayTS<String> testArray;
		
		// make a 2 x 4 array
		testArray = new RectangularArrayTS(2, 4);
		
		// fill it
		testArray.setElementAt(0, 0, "A");
		testArray.setElementAt(0, 1, "B");
		testArray.setElementAt(0, 2, "C");
		testArray.setElementAt(0, 3, "D");
		testArray.setElementAt(1, 0, "E");
		testArray.setElementAt(1, 1, "F");
		testArray.setElementAt(1, 2, "G");
		testArray.setElementAt(1, 3, "H");
		
		// print it
		printTable(testArray);


	}
	
	/**
	 * printTable() will print out a specified
	 * rectangular array in table format.
    * 
	 * @param array A RectangularArray to print
	 */
	public static void printTable(RectangularArrayTS array)
	{
		int i, j;
   
		for (i=0; i < array.rows(); i++)
		{
			for (j=0; j < array.columns(); j++)
			{
				Object o; // temporary place to store the object
				
				// getElementAt() throws an exception
				// might as well catch it incase something
				// gets changed and breaks the code
				try
				{
					o = array.getElementAt(i, j);
				}
				catch(ArrayIndexOutOfBound aioob)
				{
					System.out.println("Tried to access an index that was out of bounds!");
				}
				if (o == null) // blank space
					System.out.print("   ");
				else
					System.out.print(" " + (String) o + " ");
			}
			System.out.println(); // start next row
		}
	}
}