Activity 3.1: Removing an Element from An Array (10 pts)Copy
Activity 3.1: Removing an Element from An Array (10 pts)Copy and paste the below starter code into a file called ArrayAddDrop.javaComplete the lines of code where noted in bold.When your program is working as shown in the sample output, submit ArrayAddDrop.java to Canvas./*** @author* @author* CIS 36B*/import java.util.Scanner;public class ArrayAddDrop { public static void main(String[] args) { Scanner input = new Scanner(System.in); int indexToDrop; int numStudents = 5; //current number on roster String roster[] = new String[10]; //guesstimate of length will need roster[0] = ‘Ali’; roster[1] = ‘Bao’; roster[2] = ‘Chloe’; roster[3] = ‘Danika’; roster[4] = ‘Eduardo’; System.out.println(‘Current Roster:’); printArray(roster, numStudents); System.out.print(‘nEnter the number of the student to drop: ‘); indexToDrop = input.nextInt(); remove(roster, numStudents, indexToDrop); //decrement numStudents variable System.out.println(‘nCurrent Roster:’); printArray(roster, numStudents); System.out.println(‘Total enrolled in the class: ‘ + numStudents + ‘ students’); } /** * Removes an element from an array at a specified index * @param array the list of String values * @param numElements the current number of elements stored * @param indexToRemove where in the array to remove the element */ public static void remove(String array[], int numElements, int indexToRemove) { for (int i = indexToRemove; i < numElements – 1; i++) { array[i] = //you fill in here! } return; } /** * Print an array of Strings to the console * @param array the list of String values * @param numElements the current number of elements stored */ public static void printArray(String[] array, int numElements) { for (int i = 0; i < numElements; i++) { System.out.println(i + '. ' + array[i]); } }}Sample Output:Current Roster:0. Ali1. Bao2. Chloe3. Danika4. EduardoEnter the number of the student to drop: 2Current Roster:0. Ali1. Bao2. Danika3. EduardoTotal enrolled in the class: 4 studentshttp://deanzacollegecis.jenniferparrish.net/home/c…the link is for activity 3.2Answer the following question 1. Given the below array, the element at which index number will be shifted first when calling remove on index 1? index element 0'Al' 1 'Brianna' 2 'Chao' 3 'Darnell' 4'Ehsan' 5''2. Fill in the missing line of code for the remove method for an array:public static void remove(int array[], int numElements, int indexToRemove) { for (int i = indexToRemove; i indexToInsert; i–) {//fill in the missing line of code here}array[indexToInsert] = newValue;}http://deanzacollegecis.jenniferparrish.net/home/c…the link is for activity 4.1-4.4http://deanzacollegecis.jenniferparrish.net/home/c…link for lab2
Collepals.com Plagiarism Free Papers
Are you looking for custom essay writing service or even dissertation writing services? Just request for our write my paper service, and we'll match you with the best essay writer in your subject! With an exceptional team of professional academic experts in a wide range of subjects, we can guarantee you an unrivaled quality of custom-written papers.
Get ZERO PLAGIARISM, HUMAN WRITTEN ESSAYS
Why Hire Collepals.com writers to do your paper?
Quality- We are experienced and have access to ample research materials.
We write plagiarism Free Content
Confidential- We never share or sell your personal information to third parties.
Support-Chat with us today! We are always waiting to answer all your questions.
