Question: 5. (25 pts) Complete a method public static int minimum (ArrayList a, Comparator c) that computes the smallest integer in the array list, using the

 5. (25 pts) Complete a method public static int minimum (ArrayList

5. (25 pts) Complete a method public static int minimum (ArrayList a, Comparator c) that computes the smallest integer in the array list, using the ordering relationship that is defined by the given comparator. Also, complete the test program by declaring the comparator and calling the method to get the expected result. The comparator has to be defined in an anonymous class to get credit. Remember Java offers auto-boxing and auto-unboxing between int and Integer types. Collections. sort Comparator public static void sort (List list, Comparator super T> c) Sorts the specified list according to the order induced by the specified comparator. int compare (Tol, T 02) Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second. public Eget (int index) Returns the element at the specified position in this list. public int size() Returns the number of elements in this list. ArrayList public class MinTester { * Computes the smallest integer using the given comparison metric * @param a the ArrayList to find min of * @param c the comparator representing the comparison metric * @return the largest integer + / public static int maximum (ArrayList a, Comparator c) { // Your work goes here public static void main(String args[]) { ArrayList integers = new ArrayList(); integers.add(3); integers.add(50); integers.add(15); integers.add (20), int result - // your work goes here System.out.println(result); // prints 3)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!