Question: Complete Pair.java by defining the following constructor and methods: public Pair ( TheType aVal, TheType bVal ) Initialize the public fields firstVal to aVal and
Complete Pair.java by defining the following constructor and methods:
public PairTheType aVal, TheType bVal
Initialize the public fields firstVal to aVal and secondVal to bVal
String toString
Return a string representation of the pair in the format firstVal secondVal
int compareToPair otherPair
Return or according to whether the Pair is less than, equal to or greater than otherPair
Precedence of comparisons: firstVal, then secondVal
char comparisonSymbolPair otherPair
Return a character: or representing the result returned by compareTo
Complete LabProgram.java:
Define readIntegerPair readDoublePair and readWordPair
Take a scanner object as a parameter and return a Pair object of a specific data type
Read two values, separated by a space, from input and create a Pair object with the input values in the same order
Complete the output section of main
For each data type, output the two Pair objects separated by the character returned by comparisonSymbol
Note: main calls each read method twice to create two Pair objects of the corresponding type.
Ex: If the input for Pair objects of Integer is:
the first Pair object contains and the second Pair object contains
Ex: If the input of the program is:
one two three four
the output is:
one twothree four
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
