Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

More Books

Students also viewed these Databases questions