Source of SpeciesEqualsDemo2.java


  1: 
  2: public class SpeciesEqualsDemo2
  3: {
  4:     public static void main(String[] args)
  5:     {
  6:         Species s1 = new Species( ), s2 = new Species( );
  7:         s1.setSpecies("Klingon Ox", 10, 15);
  8:         s2.setSpecies("Klingon Ox", 10, 15);
  9:                 
 10:         testEqualsOperator(s1, s2);
 11:         testEqualsMethod(s1, s2);
 12: 
 13:         System.out.println("Now change one Klingon Ox to lowercase.");
 14:         s2.setSpecies("klingon ox", 10, 15); //Use lowercase        
 15: 
 16:         testEqualsMethod(s1, s2);
 17:     }
 18:         
 19:         private static void testEqualsOperator(Species s1, Species s2)
 20:         {
 21:         if (s1 == s2)
 22:             System.out.println("Match with ==.");
 23:         else
 24:             System.out.println("Do Not match with ==.");
 25:         }
 26: 
 27:         private static void testEqualsMethod(Species s1, Species s2)
 28:         {
 29:         if (s1.equals(s2))
 30:             System.out.println("Match with the method equals.");
 31:         else
 32:             System.out.println("Do Not match with the method equals.");
 33:         }
 34: }