Create a class ArrayTools and write these functions (static methods) in it:

  • populateRandom -- populates an array with random integers. The caller of the function should be able to specify the range of those random integers.
  • isSorted -- checks if an array of integers is sorted. Returns true if it is. Return false otherwise.
  • slice -- "slices" an integer array into an array of smaller, equally-sized integer arrays. The caller of the function decides how many slices there should be. If the original array is not evenly divisible into the specified number of slices, make the last slice appropriately smaller.
  • concatenate -- concatenates two integer arrays into one and returns it. Use System.arraycopy to perform copying.
  • linearSearch -- searches for the first occurrence of a particular value in an integer array using the linear search approach. Returns the index of the value if found.
  • binarySearch -- searches for a value in a portion of a sorted array using the binary search approach. Returns the index of the value if found.
  • stringify -- turns the array into a nicely-formatted string (e.g. {12, 1, 13, 5, 7, 1}) and returns that string
  • insertionSort -- sorts a specified portion of the array using the insertion sort algorithm. Here is the outline for your ArrayTools class:
class ArrayTools {
private static Random r = /* initialize a random number generator */;

public static void populateRandom(int[] arr, int min, int max) {
// Implementation here
}

public static boolean isSorted(int[] arr) {
// Implementation here
}

public static int[][] slice(int[] arr, int numSlices) {
// Implementation here
}

public static int[] concatenate(int[] arr1, int[] arr2) {
// Implementation here
}

public static int linearSearch(int[] arr, int key) {
// Implementation here
}

public static int binarySearch(int[] arr, int low, int high, int key) {
// Implementation here
}

public static String stringify(int[] arr) {
// Implementation here
}

public static void insertionSort(int[] arr, int low, int high) {
// Implementation here
}
}
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.