Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sybase Database Administrators Handbook

Authors: Brian Hitchcock

1st Edition

0133574776, 978-0133574777

More Books

Students also viewed these Databases questions

Question

3. Write a policy statement to address these issues.

Answered: 1 week ago

Question

2. Why has the conflict escalated?

Answered: 1 week ago