Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Create and test an utility class ArrayUtility containing various utility methods for arrays. 11. Construct a package util (under src folder), if not already created.
Create and test an utility class ArrayUtility containing various utility methods for arrays.
- 11. Construct a package "util" (under src folder), if not already created. Construct a sub-package "array" under the package sort. In this sub-package (select), Construct a public class named ArrayUtility and a public class named ArrayUtilityTest.
- 12a. In ArrayUtility class, Construct a public static method toString that receives an array of int's, a start string, a separator string and an end string. It returns a String starting with the start string, followed by the array elements separated by the separator and ending with the end string.
- 12b. In ArrayUtilityTest class, Construct a public static method toStringTest that prints the results for the following 5 lengths of arrays, using different types of brackets and separators for each: empty, singleton, two elements, 5 elements and 20 elements. Call only this class in the main method and check the results.
- 13a. In ArrayUtility class, Construct a public static method equals that receives two arrays of int's and returns true if they have the same length and equal corresponding elements.
- 13b. In ArrayUtilityTest class, Construct a public static method equalsTest that prints the results for the following 6 cases: two empty arrays, one empty and one singleton, two singleton with the same element, two singleton with different elements, two arrays with two identical elements, two arrays with two different elements. Call only this class in the main method and check the results.
- 14. In ArrayUtility and ArrayUtilityTest, design, implement and test a method named isSorted that checks if an array of int-s is already sorted, i.e. all the elements are in increasing order.
- 15. In ArrayUtility and ArrayUtilityTest, design, implement and test a method named generateIntArray that generates a random array with the provided length having elements randomly generated between a minimum and maximum value, including those values.
34 350 36 37 38 39 40 41 420 43 44 45 46 47 48 /** * Checks if two array of int-s are equals, i.e. they have the same length * and equal corresponding elements. * @param a1 the first array of int's * @param a2 the second array of int's * @return true if the two arrays are equals */ public static boolean equals(int[] a1, int[] a2) { if (al.length!=a2.length) return false; for (int i=0; i
Step by Step Solution
★★★★★
3.43 Rating (166 Votes )
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