The main method from here prompts the user to input the number of points that need to be generated, then randomly generates the specified number of points (MyPoint objects) in a certain way, and then computes the number of distinct points in two different ways: (1) by using an ArrayList, and (2) by using sorting. Two points (MyPoint objects) are said to be distinct if they differ in either their x-coordinate (x field) or their y-coordinate (y field). Notice how the equals method of the MyPoint class enables this computation when using an ArrayList, and how the compareTo method of the MyPoint class enables this computation when using Arrays.sort.
In this homework, you should add code in the main method that does the same computation (that is, counting the number of distinct points in the array arr) using a HashMap, which is an existing hash table implementation of a Map. Also have the main method print the computed number of distinct points and the time taken by this computation, exactly as is done when using an ArrayList/Sorting. See the example from class to recall how HashMap is to be used.
Note that the implementation of the hashCode method in the MyPoint class influences the time taken by your code that uses HashMap. That is because the hashCode method is one component of the hash function being used. You should optimize the time taken by your HashMap-based code by changing the hashCode method as you wish. For doing this, it will help to understand how the points in arr are being generated.
Understanding this homework requires you to understand the material covered in the lectures based on Sections 9.1 and 9.2, and in the discussion sections on November 1.
Run the completed program with the number of points being set to 10000, 50000, 100000, and 200000. For each of these four numbers, report the time taken by the ArrayList-based, sort-based, and HashMAp-based approaches as measured by the program. (For each of the four numbers, run the program a few times and report times from a run that you feel is representative.) You can report these times as a comment in the file that houses the main method.
Submit the source files into a dropbox in ICON called Homework8. This assignment is due by 11:59 pm on Monday, Nov 12.