Create an application that provides a solution

Assignment Help JAVA Programming
Reference no: EM13295516

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 detrmine the sorting order (i.e., ascending, smallest distance to largest distance).

public class Pair< F, S >

{

   private F first; // first element of a pair

   private S second; // second element of a pair

   // constructor

   public Pair( F firstElement, S secondElement )

   {

      first = firstElement;

      second = secondElement;

   } // end Pair constructor

   // get first

   public F getFirst()

   {

      return first;

   } // end method getFirst

   // get second

   public S getSecond()

   {

      return second;

   } // end method getSecond

   // set first

   public void setFirst( F firstElement )

   {

      first = firstElement;

   } // end method setFirst

   // set second

   public void setSecond( S secondElement )

   {

      second = secondElement;

   } // end method setSecond

} // end class Pair

// Exercise 18.8 Solution: PairTest.java

// Generic Pair class testing program.

 

public class PairTest

{

   public static void main( String args[] )

   {

      // create pair of integer and string

      Pair< Integer, String > numberPair =

         new Pair< Integer, String >( 1, "one" );

 

      // display original numberPair

      System.out.printf( "Original pair: < %d, %s >\n",

         numberPair.getFirst(), numberPair.getSecond() );

 

      // modify pair

      numberPair.setFirst( 2 );

      numberPair.setSecond( "Second" );

 

      // display modified numberPair

      System.out.printf( "Modified pair: < %d, %s >\n",

         numberPair.getFirst(), numberPair.getSecond() );

   } // end method main

} // end class PairTest


Attachment:- application.png

Reference no: EM13295516

Questions Cloud

Explain double bond or triple bond : For a bond between the same two atoms, which has the greatest bond enthalpy: single bond, double bond, or triple bond
Explain the kinds of things should an analyst keep in mind : It is often said that anyone with a pencil can calculate financial ratios, but it takes a brain to interpret them. Explain the kinds of things should an analyst keep in mind when evaluating the financial statements of a given firm.
Why are contingent assets and liabilities like options : Why are contingent assets and liabilities like options? What is meant by the delta of an option? What is meant by the termnotional value?
Find the potential difference across tungsten wire : A 6.0 V battery is connected to a wire made of three segments of different metals connected one after another, Find the potential difference across tungsten wire
Create an application that provides a solution : Create an application that provides a solution for problem 20.8 In addition to requirements specified in the description.
Compute the drills angular acceleration : A dentist's drill starts from rest. After2.90s of constant angular acceleration it turns at a rate of2.2104rev/min. Find the drill's angular acceleration
What is a private-equity firm : What is a private-equity firm? How do expectations of higher capital gains taxes next year help fuel the desire for private-equity firms to sell businesses? Why don't expectations of higher capital gains taxes create an offsetting dampening effect..
What amount must you deposit each year : If the account pays 4.75 percent interest, what amount must you deposit each year?
Calculate the velocity a spherical rain drop : Calculate the velocity a spherical rain drop would achieve falling from 5.00 km, in the absence of air drag

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write java program which will permit user to input data

Write the Java Program which will permit the user to input data. The data will be validated using a loop that requires the user to input the data until it is correct or in the correct range. T

  Java tv''s newest owner! java tv is the greatest tv channel

Java TV's newest owner! Java TV is the greatest TV channel ever, and it prides itself in its 24 hour interesting ' programming'. To help you run this channel you will need to write a  dynamic  program that uses  Data Lists  to store all its TV show i..

  What violations and crimes would you definitely file

What if you were a parole officer and had to decide whether or not to file complaints against your parolees? What violations and crimes would you definitely file complaints for and what would you most likely overlook and why?

  Write a java program that declares an array alpha of 50

Write a Java program that declares an array alpha of 50 elements of type double. Initialize the array so that the first 25 elements are equal to the square of the index variable, and the last 25 elements are equal to three times the index variable. O..

  Multiplexors whose control bit allows you

Design a 4-bit up/down counter that has 2 to 1 multiplexors whose control bit allows you to select between one of two counting modes up or down

  Discuss key environmental issues facing north america

Discuss the key environmental issues facing North America based on the discussion in the text. Which ones do you see threatening the quality of life in North America the most? Do you have any ideas on how these issues might be addressed?

  Create a java program to calculate the circumference

Create a Java program based on the geometric shapes. The program should begin by prompting you for the shape you want to calculate the circumference.

  Method named isallvowels that returns

Write a method named isAllVowels that returns whether a String consists entirely of vowels (a, e, i, o, or u, case-insensitively). If every character of the String is a vowel, your method should return true. If any character of the String is a non-vo..

  A game of tic-tac-toe

A game of tic-tac-toe, two players (one the computer) take turns marking an available cell in a 3 X 3 grid (a two dimensional array) with their respective tokens (either and X or an O). When one player has placed three tokens in a horizontal

  Programming exercises

Programming Exercises 1. Write an application named BadSubscriptCaught in which you declare an array of 10 first names. Write a try block in which you prompt the user for an integer and display the name in the requested position.

  Program that prompts the user to enter the year and display

Write a program that prompts the user to enter the the year and first day of the year and displays the calendar table for the year on the console. For example , if the user entered the year 2013, and 2 for tuesday, January 1, 2013, your program shoul..

  Method to calculate all primes in the range [2..n]

One commonly used method to calculate all primes in the range [2..n] is to start with the number 2, mark it as prime, and mark all its multiples (excluding itself) as not prime. Then, we find the next smallest unmarked number, mark it as prime, and m..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd