Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
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