Question: final static Scanner cin = new Scanner(System.in); final static Random rand = new Random(); final static int MAX_SIZE = 10; // amount of storage for

 final static Scanner cin = new Scanner(System.in); final static Random rand

 final static Scanner cin = new Scanner(System.in); final static Random rand = new Random(); final static int MAX_SIZE = 10; // amount of storage for the intList static int size = 0; // number of values actually in the intList static int[] intList = new int[MAX_SIZE]; /** * @param args the command line arguments */ public static void main(String[] args) { out.println("CPS 151 In-class assignment 1 by _________________________"); partA(); // partB(); } // end main private static void partA() { int position, value; out.println(" Part A: Maintain a partially filled array"); setSequenced(intList, 100, 8); size = 8; printList(intList, size, "Initial contents"); // Add code to do insert and delete out.print(" Position to delete from: "); position = cin.nextInt(); shiftUp(intList, size, position); size--; printList(intList, size, " List after deletion"); out.print(" Value to insert: "); value = cin.nextInt(); out.print("At what position? "); position = cin.nextInt(); shiftDown(intList, size, position); intList[position] = value; size++; printList(intList, size, " List after insertion"); } // end partA private static void partB() { out.println(" Part B: Insertion sort"); setRandom(intList, 100); printList(intList, MAX_SIZE, " Array before sorting"); sort(intList); printList(intList, MAX_SIZE, " Array after sorting"); } // end partB // loads sequenced values, caller responsible for mainitaining the size for // the partially filled intList private static void setSequenced(int[] intList, final int startValue, final int howMany) { // Validity check if (howMany  intList.length) terminate("setSequenced: illegal argument, howMany = " + howMany); for (int k = 0; k   This assignment has 2 parts. The main method calls the methods partA ) and then calls partB ). The skeleton code has the call to partB ) commented out. The intention is that you concentrate on the first part Once that part is completed correctly, uncomment the call to partB ) in the main method Part A The method code for partA) is complete. You need to complete the methods shiftUp ) and shiftDown (). Once these methods are written the program will allow you to delete a value from a list maintained using a partially filled array. It will also allow you to insert a value in a specific position within the list. For convenience of the programmer, we assume that the positions specified will be zero-based (i.e subscripts). You can consult sections 6.3.6 and 6.3.7 in the textbook. Note that we want the relative order of existing elements to be preserved in both of these operations Question: What are the valid value range for the variable position (in partA(0) for insertion and deletion (in terms of the variable size? [For this lab you do not need to implement the validity check] Part B Uncomment the call to partB () in "main". The code for partB () Is complete. You need to complete the method findPos ). The program then will sort a random array the insertion sort technique. Note that this part reuses the 'shiftDown' function from part A After you have completed both parts of the assignment submit the source code and screen shot as described in the document "How to submit assignments" through Isidore. The name of the project should be ICA01 and the name of the source code file should be ICA01.java Design of "findPos" method The findPos method is used to find the right place to insert a new value in a partially filled array. The partially filled array is assumed to be sorted in increasing order and if the new value is inserted at the index position (as calculated by findPos) then the resulting array will remain sorted. This is the method specification given for findPos // find the right place for item to be inserted within arr [0:size-1] private static int findPos (int[ arr, int size, int item) f Suppose size-5 and arr = { 12, 23, 45 , 67, 88). Note that there may be more elements in arr but as a partially filled array, only 5 values are relevant. These are the values returned by the method for various possible values of item. item return value from findPos (arr, 5, item) 0 18 35 45 56 3 (new 45 goes after old 45's) 4 91 You can start a position variable at 0 and keep incrementing it as long as the position issize and item is The final value is the return value from the method. Note: It is also possible to write the loop backward arr[position]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!