Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.io . BufferedReader; import java.io . FileReader; import java.io . IOException; import java.util.ArrayList; public class FinalExam _ QuestionArrayList { public static void main (

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
public class FinalExam_QuestionArrayList {
public static void main(String[] args){
String fileName = "StudentNames.txt";
String studentName;
// declare all file input/out objects, and instantiate the file streams
try (FileReader fileReader = new FileReader(fileName);
BufferedReader bufferedReader = new BufferedReader(fileReader)){
ArrayList sNameList = new ArrayList<>();
// add code to read in all student names from a file and add to the nameList object
while ((studentName = bufferedReader.readLine())!= null){
sNameList.add(studentName);
}
System.out.print("Initial list...
");
for (int idx =0; idx < sNameList.size(); idx++)
System.out.println("Student No."+ idx +":: "+ sNameList.get(idx));
/*
add code to change all the names in the odd indices of the
NameList object to the string "Mr. Sunday Movies"
*/
for (int idx =1; idx < sNameList.size(); idx +=2){
sNameList.set(idx,"Mr. Sunday Movies");
}
System.out.print("
Modified list...
");
for (int idx =0; idx < sNameList.size(); idx++)
System.out.println("Student No."+ idx +":: "+ sNameList.get(idx));
} catch (IOException e){
e.printStackTrace();
}
// write a java statement to close the input file (none needed as try-with-resources is used)
}
}

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

Next Generation Databases NoSQLand Big Data

Authors: Guy Harrison

1st Edition

1484213300, 978-1484213308

More Books

Students also viewed these Databases questions

Question

What do you mean by dual mode operation?

Answered: 1 week ago

Question

Explain the difference between `==` and `===` in JavaScript.

Answered: 1 week ago