Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider there object classes in Section 1.2: Point2D, page 77, a point is identified by its coordinates (x, y) Date, page 103, a Date is

Consider there object classes in Section 1.2:

Point2D, page 77, a point is identified by its coordinates (x, y)

Date, page 103, a Date is identified by (month, day, year)String, page 80, a String is identified by its string contents

Counter, page 85, a Counter is identified by its name

(a) Examine these object classes for their equals, hashCode, and compareTo, and determine if Point2D can be used for HashSet and separately if it can be used for TreeSet and then if Date can be used for its HashSet or TreeSet, and so on. Briefly explain your reasoning. Note that the same analysis holds for HashMap and TreeMap using the key object class.

(b) If the class doesnt have both an equals method and a hashCode method, write equals and/or hashCode for it based on the identifying fields listed above, so that it ends up with both methods.After this, HashSet should be usable for all four object classes.

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

Graph Database Modeling With Neo4j

Authors: Ajit Singh

2nd Edition

B0BDWT2XLR, 979-8351798783

More Books

Students also viewed these Databases questions

Question

1. Define and explain culture and its impact on your communication

Answered: 1 week ago