java Declare a generic interface called Pair that takes two type parameters K and V. This interface has two methods getKey that returns a value of type K, and getValue that returns a value of type V....


java




  1. Declare a generic interface called Pair that takes two type parameters K and V. This interface has two methods getKey that returns a value of type K, and getValue that returns a value of type V.




  2. Write a class OrderedPair implementing the Pair interface. The class has two instance variables which are key (of type K) and value (of type V). Define the constructor of the class OrderedPair that initializes the instance variables.




  3. In a class named Util, define a generic method, compare, which compares two Pair objects. Based on equals method inherited from the Object class, returns true if the keys and values of the two pairs are equal.


    Test your compare method.




  4. Write and test a generic method countGreaterThan that receives an array from any type that implements the Comparable interface and a parameter e of the same type. The method counts and returns the array elements that are greater than e.





Jun 10, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here