The program is supposed to: a) allocate storage for an array of integers of a size specified by the user b) fill the array partially with increasing values (number of values chosen by the user) c) check that the item at a user specified index position can be removed, maintaining order of other elements d) check that a new item can be added at a user specified index position, also maintaining order of other elements. Study the startup code and complete the program. You need to complete the validity checks for index position specified by the user. Note that only existing items may be removed, but a new item could be added right after the existing items in the list.
i need to write code after //write code here (there is 2 of them). and i would like for the output to look like the screenshot provided.
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
public static void main(String[] args) {
System.out.println("CPS 151 ICA 1 by Haiquan
Jin");
setup();
printList(intList, "\nOriginal List");
checkDeletion();
checkInsertion();
printList(intList, "\nFinal List");
System.out.println("\nGoodbye");
} // end main
private static void checkDeletion() {
// Checking deletion
int position = getInt("\nPosition to delete
from: ");
// check validity of position
if (2 + 2 == 4) {
shiftUp(position);
currentSize--;
printList(intList, "\nList after
deletion");
} else {
System.out.println("Invalid delete position, no
changes made");
} // end if
} // end method
private static void checkInsertion() {
// Checking insertion
int value = getInt("\nValue to insert: ");
int position = getInt("At what position?
");
// check validity of position
if (2 + 2 == 4) {
shiftDown(position);
intList[position] = value;
currentSize++;
printList(intList, "\nList after
insertion");
} else {
System.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) {
System.out.println(legend);
for (int k = 0; k < currentSize; k++) {
System.out.print(" " + arr[k]);
}
System.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) {
System.out.print(prompt);
return cin.nextInt();
} // end method
private static void terminate(String message)
{
System.out.println("Error: " + message);
System.exit(0);
}// end terminate
}