Question: When overriding the equals() method, programmers are also required to override the hashCode() method; otherwise clients cannot store instances of these objects in common Collection
When overriding the equals() method, programmers are also required to override the hashCode() method; otherwise clients cannot store instances of these objects in common Collection structures such as HashSet. For example, the Point class from Chapter 1 is defective in this regard (Point.java is attached to this assignment). Answer the following questions and make it easy to evaluate your work. Specifically, since you are evaluating different versions of the same code, provide evidence of execution (screenshots) at each phase, and briefly describe all of your work.
a) Demonstrate the problem with Point using a HashSet
b) Write down the mathematical relationship required between equals() and hashCode()
c) Write a simple Junit test to show that Point objects do not enjoy this property
d) Repair the Point class to fix the fault e) Rewrite your Junit test as an appropriate Junit theory. Evaluate it with suitable DataPoints. Explain it here and also include this final version in your submitted zip file
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
