Question
Create 3 different classes in a Java project Part A: Point.java class Write a Point class that simulates a 1D point, which has an x
Create 3 different classes in a Java project
Part A: Point.java class Write a Point class that simulates a 1D point, which has an x coordinate value. Implement the constructors (both default and overloading), and get method.
Part B: Point2D.java class Write a Point2D class that simulates a 2D point, which has an additional y coordinate value. Point2D inherits from Point class and Comparable interface. Implement the constructors, get method, default toString method, and compareTo method. A 2D point p1 is considered larger/s- maller than another point p2 if and only if the total sum of x/y coordinates of p1 is larger/smaller than the sum of coordinates of p2.
Part C: Test.java class
create Point2D array with five 2D points, i.e., (1.1, 2.2), (0, 3.3), (7.11, 1.2), (1.1, 7.11), (2.2, 1.1). Sort the array without passing any comparator since 2D points are already defined as comparable. Print the array after sorting.
Sample Output
Sort 2D points by both x and y coordinates (ascending order): Point (x, y): 0.0, -3.3 Point (x, y): 1.1, 2.2 Point (x, y): 2.2, 1.1 Point (x, y): 7.11, -1.2 Point (x, y): -1.1, 7.11
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