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

  Program produces 1000 integer ranging

Then your program produces 1000 integer ranging from 1to 10000 in the array and then sort them in ascending order and then print the result into data.txt file. (You may list integers separated by space or new line)

  Create four classes

Create four classes: Account.java, Checking.java, Savings.java, and AccountArray.java.

  Write a recursive program

Write a recursive program to compute the number of ways in which an integer k can be written as sum

  Drags html list items to and from a javascript array

1.Write a program which drags html list items to and from a javascript array.2. if an identical list item is already in the array, prevent the list item from dropping in the array. Give an error saying that the list item already exists in the array

  The drink machine should have a supply

When the applet starts, the drink machine should have a supply of 20 of each of the drinks. The applet should have a text field where the user can enter the amount of money he or she is giving the machine. The user can then click on a button to selec..

  Write a java program using the java graphics

Your task for this assignment is to write a Java program using the Java Graphics class to create an example of a computer generated image. This is an opportunity for you to explore computer graphics and exercise some individual creativity.

  A method with the signature public static void

A method with the signature public static void printDetails(City[] cities) that will iterate through the cities and printthe details of the city using the displayDetails(...) method.

  Write a graphical user interface class

Write a graphical user interface class called SentenceCounterGUI. It should be able to manipulate the sentence of words and have the behaviour label.

  Write a recursive public method

Write a recursive public method in our BST class that returns a reference to the information in the node containing the smallest value in the tree. The signature of the method is

  Prompts the user for three first names

Write an application that prompts the user for three first names and concatenates them in every possible two-name combination so that new parents can easily compare them to find the most pleasing baby name. Save the file as BabyNameComparison.java

  Write a program that converts number from binary to decimal

write a program that Converts a Number from Binary to Decimal  by using reading keyboard input.

  Shows the users name and program name

Java program, the program has a page that shows the users name and program name. a second jpanel that shows 4 buttons (circle square rectangle and oval) the problem i am having is that my program is not dropping where i click and the shapes are not s..

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