Question: JAVA Create a class CopyAndResizeArray to do the following work: 1. Declare and allocate an array of 10 Strings. I'll call it 'array' but you

JAVA

Create a class CopyAndResizeArray to do the following work:

1. Declare and allocate an array of 10 Strings. I'll call it 'array' but you may name it whatever you like.

2. Read all lines of the file top-ten-minus8.txt from disk into your array of 10 elements.

a. Should you use Scanner.next() or .nextLine()?

b. Don't forget to use Scanner.hasNextLine() in your loop to make sure you read all the data.

c. The list is missing the #8 school, North Carolina Central University.

4. Declare and allocate a newArray of 10 Strings. You will copy the contents of array --> newArray.

5. Declare and set an integer insertionIndex to value 7 (the 8th element of the array with 0-based indexing)

6. Use a loop to copy the first seven elements from array to newArray.

7. Set newArray[insertionIndex] = "North Carolina Central University"

8. Use a loop to copy the remaining 2 strings from the end of array to the end of newArray.

9. Use a loop to print out the 10 elements of newArray.

// This code reads a file with the top 10 HBCUs by enrollment, // then adds the #8 school at array[7]. To do so it needs to // allocate a new array and copy data in multiple steps.

// TODO: Set up your imports as needed.

public class CopyAndResizeArray { // TODO Maybe need a 'throws ...' in your main() header line. public static void main(String[] args) { int arraySize = 10; // We want to hold top 10 schools. String filename = "top-ten-minus8.txt";

// TODO: Allocate your array of arraySize (10) Strings.

// TODO: Set up a scanner to read the file.

// TODO: Read the file into your array, one line of text per // array element. Keep reading until the file has no more lines // of text to read.

// Argh, we have to copy and resize in order to insert. String missingSchool = "North Carolina Central University"; // TODO: Set your inserting index at 7, the position of the missing school. int insertionIndex = 7; // TODO: Allocate your newArray of arraySize (10) Strings.

// TODO: Use a loop to copy the first elements from array --> newArray.

// TODO: Add the missing school at the insertionIndex.

// TODO: Use a loop to copy the rest of the array from array --> newArray. // TODO: Print out the new array to prove we did the work correctly.

} }

CONTENTS OF TEXT FILE

North Carolina A&T State University Texas Southern University Florida A&M University Howard University Prairie View A&M University Jackson State University Tennessee State University Morgan State University Albany State University

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!