/*This class is used to store salary info. for a single employee
The constructor and setEmpInfo both have a subtle bug which you might try to pinpoint*/

public class Employee {
  private String name;
  private int salary; 
  private Address address;
  
  public Employee(String name, int salary, Address address) {
    this.name = name;
    this.salary = salary;
    this.address = address;
  }
  public Employee(Employee emp2) {
    //does this work? why or why not?
    this.name = emp2.name;
    this.salary = emp2.salary;
    this.address = emp2.address;
  }

  //accessors
  public void printEmpInfo() {
    System.out.println("Employee: " + name + ", salary: " + salary + ",000");
    System.out.println("Lives at: " + address.getNumber() + " " + address.getStreet());
  }  
  
  public String getName() { return name; }
  public int getSalary() { return salary; }

  //the new material is here
  //Note: for simplicity, I do not compare the addresses here.  
  //practice how you would change this method to compare addresses as well 
  public boolean equals(Employee emp2) {
    
    //both the names and the salaries must be equal if "this" and "emp2" are equal
    //notice we can compare the primitive (salary) directly, but the reference (String)
    //must be compared using .equals()
    
    return( emp2.name.equals(name) && emp2.salary == salary);
  }
  
  //mutators
  public void setEmpInfo(Employee emp2) {
    //does this work? why or why not?
    this.name = emp2.name;
    this.salary = emp2.salary;
    this.address = emp2.address;
  }
  public void setName(String name) {
    this.name = name;
  }
  public void setSalary(int salary) {
    this.salary = salary;
  }
  public void setAddress(Address address) {
    this.address = address;
  }  
  
  //make it easy for users to change street and number separately
  public void setStreetName(String streetName) {
    address.setStreet(streetName);
  }  
  public void setHouseNumber(int num) {
    address.setNumber(num);
  }  
}
