package cn.edu.bjut.chapter6; public class Name { private String firstName, lastName; public Name(String firstName, String lastName) { this.firstName = firstName; this.lastName = lastName; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } @Override public String toString() { return "[" + lastName + ", " + firstName + "]"; } @Override public boolean equals(Object obj) { if ((obj == null) || !(obj instanceof Name)) { return false; } if (this == obj) { return true; } Name other = (Name) obj; return (firstName.equalsIgnoreCase(other.firstName) && lastName.equalsIgnoreCase(other.lastName)); } @Override public int hashCode() { return (firstName.toLowerCase().hashCode() * 10 + lastName.toLowerCase().hashCode()); } }