Question
(USE INHERITANCE extends/implements) Part 2 Inheritance, comparable and comparator Part A: Point.java Write a Point class that simulates a 1D point, which has an x
(USE INHERITANCE extends/implements)
Part 2 Inheritance, comparable and comparator Part A: Point.java Write a Point class that simulates a 1D point, which has an x coordinate value. Implement the constructors (both default and overloading), get method, and default toString method.
Part B: Test.java Generate a Point array1 of five 1D points, (1.1, 2.2, 0, 7, 1.1) Sort the 1D point array using the Arrays.sort method by passing your own comparator using anonymous inner class style. 1D points are compared based on their x coordinates. (Print the array after sorting) After, Sort the 1D point array again in reverse order by pass a slightly different comparator using lambda expression style. (Print the array after sorting.)
Sample Output Sort 1D points by x coordinate (ascending order): Point (x): -2.2 Point (x): 0.0 Point (x): 1.1 Point (x): 1.1 Point (x): 7.0 Sort 1D points by x coordinate (descending order): Point (x): 7.0 Point (x): 1.1 Point (x): 1.1 Point (x): 0.0 Point (x): -2.2
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started