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 { private F f; private S s;

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!