/**
 * TestJedi2.java -- this is an application/main class that serves as a tester 
 * for our Jedi2.java program.
 * It has been created to show how to compare objects of reference data 
 * types .  Please run and understand the following clearly.
 *
 * CSCE 155 Fall 2005
 * @author Leen-Kiat Soh
 * @version 1.0
 */

class TestJedi2  {

   /**
    * This main method allows TestJedi2 to be invoked as an application. It 
    * expects no arguments.  It runs two tests, to show (1) how two Jedi2
    * objects can be compared using "getters", and (2) how one Jedi2 object can
    * be compared to another given Jedi2 object using an instance method
    * "compareTo".
    * The third test is key to understand comparisons between two objects.  If
    * we use the equal sign to compare two objects, we are *not* comparing the
    * contents of the objects; instead, we are comparing the memory addresses
    * of the two objects. If the memory addresses are the same, then that means
    * we are actually having two variable names for exactly the same object.
    */

   public static void main(String[] args)  {


      // declaring and creating two Jedi2 objects.
      Jedi2 luke = new Jedi2(5, "luke");
      Jedi2 obiwan = new Jedi2(5, "obiwan");


      // Test 1:  Doing it the difficult way
      if (luke.getName().equals(obiwan.getName()) &&
	  luke.getForce() == obiwan.getForce())
	 System.out.println("they are equal");
      else
	 System.out.println("they are not equal");
     

      // Test 2:  Doing it the elegant and easy way
      // Imagine that you have thousands of objects to compare, and each object
      // has 100s of data member values.  Test 2 approach is much more elegant 
      // and easier to manage.

      if (luke.compareTo(obiwan))
	 System.out.println("they are equal");
      else
	 System.out.println("they are not equal");


      // Test 3:  Checking whether the two objects are exactly the same --
      // pointing to exactly the same memory address

      obiwan = luke;

      if (luke == obiwan)
	 System.out.println("they are exactly the same object");
      else
	 System.out.println("they are not the same object");

   }

}  // end TestJedi2 class


