Question: Java removeDuplicates Write a method called removeDuplicates that takes a list of Point objects and that removes duplicates from the list, returning a set of

Java

removeDuplicates

Write a method called removeDuplicates that takes a list of Point objects and that removes duplicates from the list, returning a set of the Point objects from the list. For example, if a list called points contains the following values:

[[x=1,y=3], [x=7,y=7], [x=1,y=3], [x=7,y=8], [x=1,y=3], [x=7,y=7], [x=7,y=8], [x=4,y=2], [x=7,y=8], [x=7,y=8], [x=4,y=2], [x= 4,y=2]]

then the call removeDuplicates(points) should leave the list storing:

[[x=1,y=3], [x=7,y=7], [x=7,y=8], [x=4,y=2]]? 

and the set returned should store the same values. Your method should preserve the order of values in the list (removing duplicates that come later in the list), but the values in the set can appear in any order.

You may construct iterators and the set to be returned, but you are not allowed to construct other structured objects (no string, set, list, etc.).

Recall the point class has the following methods:

Point(x, y) constructs a point at position (x, y) Point() constructs a point at position (0, 0) getX() returns the x coordinate of the point getY() returns the y coordinate of the point equals(other) returns true if the points have the same (x, y), false otherwise toString() returns a string in the form "(x, y)"

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!