Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need a code under both //Write the code lines to print the sample output given final static Scanner cin = new Scanner(System.in); static int currentSize;

Need a code under both "//Write the code" lines to print the sample output given

 final static Scanner cin = new Scanner(System.in); static int currentSize; // number of values actually in the intList static int[] intList; // reference to the partially filled array storage /** * @param args the command line arguments */ public static void main(String[] args) { out.println("CPS 151 ICA 1 by _________________________"); setup(); printList(intList, " Original List"); checkDeletion(); checkInsertion(); printList(intList, " Final List"); out.println(" Goodbye"); } // end main private static void checkDeletion() { // Checking deletion int position = getInt(" Position to delete from: "); // check validity of position if (2 + 2 == 5) { shiftUp(position); currentSize--; printList(intList, " List after deletion"); } else { out.println("Invalid delete position, no changes made"); } // end if } // end method private static void checkInsertion() { // Checking insertion int value = getInt(" Value to insert: "); int position = getInt("At what position? "); // check validity of position if (2 + 2 == 5) { shiftDown(position); intList[position] = value; currentSize++; printList(intList, " List after insertion"); } else { out.println("Invalid insert position, no changes made"); } // end if } // end method // fills array with increasing values private static void fillArrayInc(final int startValue, final int howMany) { // Validity check if (howMany < 1 || howMany > intList.length) { terminate("fillArrayInc: illegal argument, howMany = " + howMany); } for (int k = 0; k < howMany; k++) { intList[k] = startValue + k; } currentSize = howMany; } //end setSequenced // prints partially filled array with a legend private static void printList(final int[] arr, final String legend) { out.println(legend); for (int k = 0; k < currentSize; k++) { out.print(" " + arr[k]); } out.println(); } // end printList // move items from pos+1:currentSize-1 one position up (lower subscripts) private static void shiftUp(int pos) { // Write the code } // end shiftUp // move items from pos:currentSize-1 one position down (higher subscripts) private static void shiftDown(int pos) { // Write the code } // end shiftDown private static void setup() { int maxSize, initSize; maxSize = getInt("Enter the maximum size: "); intList = new int[maxSize]; initSize = getInt("Enter the starting size: "); if (initSize > maxSize) { terminate("starting size cannot be greater than maximum size"); } fillArrayInc(100, initSize); } // end method private static int getInt(String prompt) { out.print(prompt); return cin.nextInt(); } // end method private static void terminate(String message) { out.println("Error: " + message); exit(0); } // end terminate

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 11g SQL

Authors: Jason Price

1st Edition

0071498508, 978-0071498500

More Books

Students also viewed these Databases questions

Question

what is a peer Group? Importance?

Answered: 1 week ago