/**
 * TestArray2.java -- This is an application/main class that illustrates some
 * properties of 2-dimensional arrays.  It also demonstrates how to perform a
 * swap of array elements.
 *
 * JDEP183H Fall 2008
 * @author Leen-Kiat Soh
 * @version 1.0
 */

class TestArray2 {

   public static void main (String[] args)  {


      // Table 1 -- a 2-D array, fixed length
      //
      
      double[][] table1;
      table1 = new double[4][5];

      System.out.println("table1's array length is " + table1.length);


      for (int i = 0; i < table1.length; i++)   {
         System.out.println("table1[" + i + "]'s array length is " 
			     + table1[i].length);
	 }

     

      table1[0][0] = 1.0;
      table1[0][1] = 2.0;
      table1[0][2] = 3.0;
      table1[0][3] = 4.0;
      table1[0][4] = 5.0;

      for (int i = 0; i < table1[0].length; i++)
	 System.out.println("value at [" + i + "] is " + table1[0][i]);



      // Table 2 -- a 2-D array, fixed length in one dimension, but ...?
      //
      double[][] table2;
      table2 = new double[4][];
      table2[0] = new double[1];
      table2[1] = new double[10];
      table2[2] = new double[20];
      table2[3] = new double[30];

      System.out.println("table2's array length is " + table2.length);

      for (int i = 0; i < table2.length; i++)   {
         System.out.println("table2[" + i + "]'s array length is " 
			     + table2[i].length);
	 }

  
      double[][] table3 = { { 5.8, 5.4, 5.6, 5.7, 5.8 },
			 { 6.9, 6.7, 5.4, 4.5 } };

   System.out.println("table3's array length is " + table3.length);

   for (int i = 0; i < table3.length; i++)   {
      System.out.println("table3[" + i + "]'s array length is " 
			     + table3[i].length);
	 }


   // Performing a swap
   //
   
   Jedi persons[] = new Jedi[10];
   persons[0] = new Jedi(10,"Darth");
   persons[1] = new Jedi(10,"Anakin");
   Jedi temp = new Jedi(10,"Luke");

   temp = persons[0];
   persons[0] = persons[1];
   persons[1] = temp;
   temp = null;

   persons[0].printInfo();
   persons[1].printInfo();
   temp.printInfo();

   }  // end main

}  // end TestArray2

