Question: Create an application that provides a solution for problem 20.8 In addition to requirements specified in the description. The class must satisfy the following -Default
Create an application that provides a solution for problem 20.8 In addition to requirements specified in the description. The class must satisfy the following
-Default Constructor
-Two argument constructor for data used to initialize "first" and "second"
-"toString" method for displaying the "first" and "second" data elements
-Creates a "Comparator" object (to be used by the sort method; i.e. create an instance of a class that implements the interface [must override "compare" and "equals" methods])
The application must create an ArrayList of 5 Pair objects and then display the contents in sorted order largest to smallest, based on the method used to compare "Pair" objects. The class only supports types that extend Number. Assume the "Pair" objects contain x, y coordinates. Therefore calculate the distance from a 0,0 coordinate to determine the sorting order (i.e., ascending, smallest distance to largest distance).
Please show .java if code is separated by class.
Pair.java
| public class Pair public Pair(F first, S second) { this.f = first; this.s = second; } public F getF() { return f; } public void setF(F first) { this.f = first; } public S getS() { return s; } public void setS(S second) { this.s = second; } } |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
