Assignment 10:

Due Date: 20 April 2010 – 7:20 PM

 

Purpose:

The contract for equals().

Assignment Details:

 

We will explore the equals() contract as discussed in both Liskov and Bloch books.

As it happens, Liskov's discussion of equals() for the Point2 and Point3 classes (see section 7.9.3, page 182) is wrong.

o Implement enough of Point2 and Point3 that you can instantiate Point2 and Point3 objects and show which part of the equals() contract is violated.

o Implement hashCode() for both Point2 and Point3. Use Bloch's recipe. Note that if equals() is broken, it is impossible for hashCode() to satisfy its contract. Hence, your hashCode() will also be broken.

o Provide JUnit tests to show first that equals() in Liskov's Point is broken and second to show that hashCode() is also broken.