Question: A Java problem. In this problem you will write several static methods to work with arrays and ArrayLists. Remember that a static method does not

A Java problem. In this problem you will write several static methods to work with arrays and ArrayLists. Remember that a static method does not work on the instance variables of the class. All the data needed is provided in the parameters. Call the class Util. Notice how the methods are invoked in UtilTester.

1. public static int min(int[] array) gets the minimum value in the array 2. public static boolean contains(String[] array, String letter)determines if the array contains a word that starts with the given letter. Returns true if it does, otherwise returns false. The comparison is case-insensitive. 'A' and 'a' are counted as the same letter 3. public static ArrayList contains(ArrayList list, char letter)gets an ArrayList of all the strings in the given ArrayList that contain with the given letter. The comparison is case-insensitive. 'A' and 'a' are counted as the same letter

The last two methods are an example of overloading.

Provide Javadoc.

------------------------------------------------------------------------------------------------------------------------

UtilTester.java

import java.util.ArrayList; public class UtilTester { public static void main(String[] args) { //testing min method int[] numbers = {5, 8, 4, 6, 2, 1, 7, 3}; System.out.println(Util.min(numbers)); System.out.println("Expected: 1"); int[] numbers2 = {2, 9, 4, 6, 5, 8, 7, 3}; System.out.println(Util.min(numbers2)); System.out.println("Expected: 2"); int[] numbers3 = {10, 9, 4, 6, 5, 8, 7, 3}; System.out.println(Util.min(numbers3)); System.out.println("Expected: 3"); //testing first contains String[] javaIdentifiers = {"Integer", "Double", "Float", "Char", "boolean", "long", "short", "byte"}; System.out.println(Util.contains(javaIdentifiers,"c")); System.out.println("Expected: true"); System.out.println(Util.contains(javaIdentifiers, "x")); System.out.println("Expected: false"); System.out.println(Util.contains(javaIdentifiers,"B")); System.out.println("Expected: true"); //testing second contains ArrayList words = new ArrayList(); System.out.println(Util.contains(words, 'b')); System.out.println("Expected: []"); words.add("Big"); words.add("Java"); words.add("is"); words.add("best"); words.add("Be"); words.add("the"); words.add("computer"); words.add("CS46A/B"); System.out.println(Util.contains(words, 'e')); System.out.println("Expected: [best, Be, the, computer]"); System.out.println(Util.contains(words, 'B')); System.out.println("Expected: [Big, best, Be, CS46A/B]"); System.out.println(Util.contains(words, 'a')); System.out.println("Expected: [Java, CS46A/B]"); System.out.println(Util.contains(words, 'k')); System.out.println("Expected: []"); } } 

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!