Question: Please help me create this program in Java. I cannot seem to get it to work. Also given for the program: public class Sorted_Array {
Please help me create this program in Java. I cannot seem to get it to work.

Also given for the program:
public class Sorted_Array { // Global constants final int CAPACITY = 10; final int MAXRANGE = 99; private int[] arr; private int elements; // Count of random elements
public Sorted_Array() { arr = new int[CAPACITY]; elements = 0; }
int binarySearch(int low, int high, int key) { if (high
int mid = (low + high) / 2; if (key == arr[mid]) return mid; if (key > arr[mid]) return binarySearch((mid + 1), high, key);
return binarySearch(low, (mid - 1), key); }
// Inserts a key in arr[] of given // capacity. n is current size of arr[]. // This function returns n+1 if insertion // is successful, else n. void insertSorted(int key) { // Cannot insert more elements if n is already // more than or equal to capcity if (elements >= CAPACITY) { System.out.println("Array is full, cannot insert "+ key); return; } int i; for (i = elements - 1; (i >= 0 && arr[i] > key); i--) arr[i + 1] = arr[i];
arr[i + 1] = key;
elements ++; }
void deleteElement(int key) { // Find position of element to be deleted int pos = binarySearch(0, elements - 1, key);
if (pos == -1) { System.out.println("Element not found"); return; }
// Deleting element int i; for (i = pos; i
elements --; } void deleteIndex(int idx) { int num; if (idx > elements - 1) System.out.println("Invalid index"); else { num = arr[idx]; deleteElement(num); } }
int getIndexOf(int key) { return binarySearch(0, elements-1, key); } void display() { for (int i= 0; i Then write a program that displays the following menu: 1. Fill array 2. Add a number 3. Find the index of a number 4. Remove number at index 5. Remove number 6. Quit Methodality We suggest that you develop your program incrementally. Meaning one menu item at a time. If it works correctly, add another one and so on. Use an int array of size 10. There should be no global variables at all, only constants are allowed. Use a variable to store the number of items the array contains (not all 10 elements will hold user data). For each menu item 0-6, write a method that takes the array name, the number of items in addition to other arguments (eg: the size of the array) if/when needed. 1. Fill array: Asks user how many numbers to fill the length of the partially filled array). Validate the user entered number (1-10 inclusive). Fill the sorted array with random numbers 1-99 inclusive. The number of elements should be equal to the value specified by the user. Must use the provided insertSorted method. You may not add a number then sort the array. 2. Add a number: If array is full displays a message indicating that, otherwise add a random number in the correct position to the sorted array. You may not add a number then sort the array. 3. Find index of a number: Displays the index of a number specified by the user fit exists otherwise a message saying that the number is not found. 4. Remove number at index: Ask the user to enter the index. Remove the number at the specified index or display error message if the specified index is outside the current partially filled array size. 5. Remove number: Ask the user to enter a number, remove it if it exists otherwise display a message to indicate that it does not exist. Must use the provided deleteElement method. For searching, you must use the provided binarySearch method. The provided methods may not be modified. Display the sorted array every time the menu is displayed
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
