Test the implementation of badarrayexception and arrayutils


Assignment:

Create a custom Java exception class named BadArrayException that has two constructors:

- A default constructor with no arguments.

- A constructor taking a String parameter (the exception message) that must be passed to the parent Exception(String) constructor.

Create a Java class named ArrayUtils that contains the following public methods. The class must implement all the search and copy logic for these methods. It can not use array methods from the Java API.

1. public static int minValue(int[] list)

This static method searches its parameter array to locate the minimum value, and returns it. Do not use sorting to find the minimum value in the array. The array may contain any negative, 0, and/or positive values. If the array parameter is length 0, it must throw a BadArrayException with the message "Array is empty".

2. public static int[] copyRange(int[] list, int startIndex)

This static method copies the specified range of elements from the parameter array into a new array, and returns it. The initial index of the range (startIndex) must lie between 0 and list.length, inclusive. The range is [startIndex, Index of last element in the list]. If the startIndex parameter is less than 0 or greater than list.length, it must throw an ArrayIndexOutOfBounds exception with startIndex as the exception object parameter.

3. public static int indexOf(int[] list, int searchValue)

This static method searches its parameter array to locate the first occurrence of the parameter searchValue, and returns its index position if found, or -1 if not found. If the array parameter is length 0, it must return -1.

4. public static int lastIndexOf(int[] list, int searchValue)

This static method searches its parameter array to locate the last occurrence of the parameter searchValue, and returns its index position if found, or -1 if not found. If the array parameter is length 0, it must return -1.

If the array parameter is null, methods must throw a BadArrayException with the message "Array is null". These methods should not catch the BadArrayException they throw due to a null or empty array parameter. The exception is thrown back to the calling code to handle.

Test the implementation of BadArrayException and ArrayUtils classes :

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Test the implementation of badarrayexception and arrayutils
Reference No:- TGS01934635

Now Priced at $30 (50% Discount)

Recommended (93%)

Rated (4.5/5)