Question: Question. Consider there object classes in Section 1.2: Point2D, a point is identifified by its coordinates (x, y) Date, a Date is identifified by (month,

Question. Consider there object classes in Section 1.2: Point2D, a point is identifified by its coordinates (x, y) Date, a Date is identifified by (month, day, year) String, a String is identifified by its string contents Counter, a Counter is identifified by its name

(a) Examine these object classes for their equals, hashCode, and compareTo, and determine if Point2D can be used for HashSetand separately if it can be used for TreeSetand 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 doesn't 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!