Repairing a catalog hash-code audit

A catalog program has seven distinct, non-null CatalogEntry objects. Its equality method satisfies the Object.equals contract and considers two entries equal exactly when their product IDs match. The table shows proposed hashCode() results for a test run.


Entry

Product ID

Proposed hash code

A

501

312

B

501

312

C

501

99

D

608

99

E

608

312

F

712

99

G

904

700


You are correcting the proposed results before running the test. A changed entry means one row receives a different hash-code integer. Any Java int value may be used. The corrected results must satisfy the relationship between equals and hashCode; the equality results and product IDs remain fixed. Each corrected result will remain stable throughout the run.


Determine these three quantities, each as an exact integer count:

  • The minimum number of changed entries required.
  • The maximum number of distinct hash codes possible when exactly that minimum number of entries is changed.
  • The maximum number of distinct hash codes possible when there is no limit on changed entries.
Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More The Object Class Questions: