Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Copy and paste the below starter code into a file called ArrayAddDrop.java Complete the lines of code where noted in bold. When your program is

  • Copy and paste the below starter code into a file called ArrayAddDrop.java
  • Complete 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 * 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(" Enter the number of the student to drop: "); indexToDrop = input.nextInt(); remove(roster, numStudents, indexToDrop); //decrement numStudents variable System.out.println(" Current 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. Ali 1. Bao 2. Chloe 3. Danika 4. Eduardo Enter the number of the student to drop: 2 Current Roster: 0. Ali 1. Bao 2. Danika 3. Eduardo Total enrolled in the class: 4 students

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

Computer Aided Database Design

Authors: Antonio Albano, Valeria De Antonellis, A. Di Leva

1st Edition

0444877355, 978-0444877352

More Books

Students also viewed these Databases questions

Question

design a simple disciplinary and grievance procedure.

Answered: 1 week ago

Question

2. What process will you put in place to address conflicts?

Answered: 1 week ago