Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given the partial code below, fill in the missing lines of code described by the commented sections. The program declares an ArrayList object of type

Given the partial code below, fill in the missing lines of code described by the commented sections. The program declares an ArrayList object of type String. Per the comments, write java statements to open a file named "StudentNames.txt" add the names stored in the input file to the ArrayList object called sNameList. Write java statements to change all the names in the odd indices of the ArrayList object to the string "Mr. Sunday Movies". Run the completed program and paste a screenshot of the input file and the output.

public class FinalExam_QuestionArrayList {

public static void main(String []args)/* add missing exception here */{

String fileName = "StudentName.txt";

String studentName;

// declare all file input/out ojects, and instantiate the file streams

/* add code here */

ArrayList sNameList = new ArrayList<>();

while(studentName=scanner.nextInt)

sNameList.add(studentName);

/*

add code to read in all student names from a file and add to the

nameList object

*/

System.out.print("Initial list... ");

for(int idx = 0; idx < sNameList.size(); idx++)

System.out.println("Student No. " + idx + ":: " + sNameList.toString());

/*

add code to change all the names in the odd indices of the

NameList object to the string "Mr. Sunday Movies"

*/

System.out.print(" Modified list... ");

for(int idx = 0; idx < sNameList.size(); idx++)

System.out.println("Student No. " + idx + ":: " + sNameList.toString());

}

}

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

Step: 3

blur-text-image

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

Database Management An Organizational Perspective

Authors: Richard T. Watson

1st Edition

0471305340, 978-0471305347

More Books

Students also viewed these Databases questions

Question

What must a creditor do to become a secured party?

Answered: 1 week ago

Question

When should the last word in a title be capitalized?

Answered: 1 week ago