/** main program to test class RectArray */
public class TestRectArray{
   
   /** Create a rectangular  int array with 3 rows and 5 columns
       but stored in an instance of RectArray. Initially, set each
       element [r][c] to r*100+c. Print the array in row major order
       and column major order. Then wait for an integer
       to be typed in.
     */
   public static void main(String pars[]) {
      int rw= 3;    // number of rows in d
      int cl= 5;    // number of columns in d
      RectArray d= new RectArray(rw,cl);
      
      // Fill each element d[r,c] with the value r*100+c
         for (int r= 0; r != d.getRows(); r= r+1)
             for (int c= 0; c != d.getCols(); c= c+1) {
               d.setElementAt(r,c, r*100+c);
             }
             
      printRow(d);
      System.out.println();
      printCol(d);
      int end= JLiveRead.readLineInt();
   }
      
   /** Print array d in column major order */
   public static void printCol(RectArray d) {
      System.out.println("d has " + d.getRows() + " rows and " +
                                    d.getCols() + " columns.");                               
      // inv: The first c columns have been printed
      for (int c= 0; c != d.getCols(); c= c+1) {
         // Print column c
            System.out.print("col " + c + " is: ");
            for (int r= 0; r != d.getRows(); r= r+1) {
              int el= d.elementAt(r,c);
              System.out.print(el + "  ");
            }
            System.out.println();
     }
   }
   
   /** Print array d in row-major order */
   public static void printRow(RectArray d) {
      System.out.println("d has " + d.getRows() + " rows and " +
                                    d.getCols() + " columns.");                               
      // inv: The first r rows have been printed
      for (int r= 0; r != d.getRows(); r= r+1) {
         // Print row r
            System.out.print("row " + r + " is: ");
            for (int c= 0; c != d.getCols(); c= c+1) {
              int el= d.elementAt(r,c);
              System.out.print(el + "  ");
            }
            System.out.println();
     }
   }

}
