P18.1 Write a static generic method PairUtil.minmax that computes the minimum and maximum elements of an array of type T and returns a pair containing the minimum and maximum value. Require that the array elements implement the Measurable interface.
public interface Measurable{ /** Computes the measure of the object. @return the measure */ double getMeasure();}
In class P18_1, test your method by providing an Array of Measurable elements and returning a
Pair containing min and max values.
Example:
Measurable
Output:
(1.0, 99.0)
P18.4 Make the Measurable interface into a generic class. Provide a static method that returns the largest element of an ArrayList
In class P18_4, supply a test case by instantiating Measurable elements, add them to an
ArrayList and return the largest element.
Example:Measurable
E22.7 Write a program WordCount that counts the words in one or more files. Start a new thread for each file. Also, the last active thread also prints a combined count. Use locks to protect the combined word count and a counter of active threads.For example, if you call
➢ java WordCount report.txt address.txt Homework.java
then the program might print
address.txt: 1052Homework.java: 445report.txt: 2099Combined Count: 3596