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
Step: 1
Get Instant Access with AI-Powered 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