import java.awt.Rectangle;

public class EmployeeMain {
  public static void main(String [] args) {
  
    //first, let's quickly see what is NOT the correct way to compare reference types.
    //create two rectangles that are clearly the same
    Rectangle r1 = new Rectangle(2, 3, 4, 5);
    Rectangle r2 = new Rectangle(2, 3, 4, 5);
    
    //this line prints "false"
    System.out.println("Comparing two reference variables directly gives: ");
    System.out.println(r1==r2);
    

    //The reason is what's actually inside the variables r1 and r2 are different--recall, r1
    //and r2 are references, so they contain the locations in memory (of r1 and r2 resp.)
    //Clearly, users want to know if the two rectangles have the same dimensions, etc. and don't
    //care much for the memory locations..
    
    //The correct way to do this:
    System.out.println("Using the equals() method gives: ");
    System.out.println(r1.equals(r2));
    System.out.println("----------------------------------");
    
    //Using the employee class, this might work as follows:
    Employee emp1 = new Employee("Fred", 12, new Address("Main St.", 400));
    Employee emp2 = new Employee("Jane", 70, new Address("Main St.", 402) );
    
    emp1.printEmpInfo();
    emp2.printEmpInfo();
    
    System.out.println("Emp1 and Emp2 are the same: " + emp1.equals(emp2));
    
    //notice what happens if we assign emp1 to emp2.  
    emp2 = emp1;
    
    System.out.println("After <emp2 = emp1;> the values are the same: ");          
    System.out.println(emp1.equals(emp2));
    System.out.println(emp1 == emp2);
    
    //this is called "aliasing" and means that two reference variables refer to literally
    //the EXACT SAME OBJECT (not two different objects w/ equal instance fields)
  }
}
