Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored 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