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 with AI-Powered 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

Students also viewed these Databases questions

Question

Explain the importance of Human Resource Management

Answered: 1 week ago

Question

Discuss the scope of Human Resource Management

Answered: 1 week ago

Question

Discuss the different types of leadership

Answered: 1 week ago

Question

Write a note on Organisation manuals

Answered: 1 week ago