Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java programming complete the overridden methods `hashCode()` and `equals()` correctly, according to the contract of these methods. Your hash function should be as uniform as

 Java programming complete the overridden methods `hashCode()` and `equals()` correctly, according to the contract of these methods. Your hash function should be as uniform as possible. In implementing your hash code, you may *not* use the default Java implementations in `Object.hashCode()` or `Objects.hashCode()`.
 * This class represents a street address within the Australian Capital Territory, * for example "108 North Road 2601". */ public class Q5Address { /** * The street number of the address (must be greater than zero) e.g. 108. */ int streetNumber; /** * The street name is a string of ASCII characters e.g. "North Road" */ String streetName; /** * The postcode is a number from 0 to 9999. */ int postCode; public Q5Address(int streetNumber, String streetName, int postCode) { if (streetName == null) throw new IllegalArgumentException("Street name may not be null!"); this.streetNumber = streetNumber; this.streetName = streetName; this.postCode = postCode; } /** * @return a hash code value for this object. * In implementing this method, you may *not* use the default Java * implementations in Object.hashCode() or Objects.hash(). * @see Object#hashCode() */ @Override public int hashCode() { // FIXME complete this method return new Random().nextInt(2); } /** * @return true if this address is equal to the provided object * @see Object#equals(Object) */ @Override public boolean equals(Object object) { // FIXME complete this method return false; } @Override public String toString() { return streetNumber + " " + streetName + " " + postCode; } // DO NOT DELETE OR CALL THIS METHOD int passThroughHash() { return super.hashCode(); } } 

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

Step: 3

blur-text-image

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

Database Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

More Books

Students also viewed these Databases questions

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago