package Q2; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; public class Question2 { public static void main(String[] args) throws FileNotFoundException { /** * Part a * Finish creating an ArrayList called NameList that stores the names in the file Names.txt. */ ArrayList NameList; /** * Part b * Replace null on the right-hand-side of the declaration of the FileInputStream object named inputStream * so that it is initialized correctly to the Names.txt file located in the folder specified in the question description */ FileInputStream inputStream = null; Scanner scnr = new Scanner(inputStream); //Do not modify this line of code /** * Part c * Using a loop and the Scanner object provided, read the names from Names.txt * and store them in NameList created in Part a. */ /** * Part d * Reorder the names in the ArrayList so that they appear in reverse alphabetical order. */ // System.out.println("NameList after correct ordering: " + NameList); //Uncomment when you are ready to test Part d /** * Part e * Change the spelling of the name "Petor" to "Peter" in *NameList*. */ // System.out.println("NameList after corrected spelling: " + NameList); //Uncomment when you are ready to test Part e } }
package Q2;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class Question2 {
public static void main(String[] args) throws FileNotFoundException {
/**
* Part a
* Finish creating an ArrayList called NameList that stores the names in the file Names.txt.
*/
ArrayList<String> NameList;
/**
* Part b
* Replace null on the right-hand-side of the declaration of the FileInputStream object named inputStream
* so that it is initialized correctly to the Names.txt file located in the folder specified in the question description
*/
FileInputStream inputStream = null;
Scanner scnr = new Scanner(inputStream); //Do not modify this line of code
/**
* Part c
* Using a loop and the Scanner object provided, read the names from Names.txt
* and store them in NameList created in Part a.
*/
/**
* Part d
* Reorder the names in the ArrayList so that they appear in reverse alphabetical order.
*/
// System.out.println("NameList after correct ordering: " + NameList); //Uncomment when you are ready to test Part d
/**
* Part e
* Change the spelling of the name "Petor" to "Peter" in *NameList*.
*/
// System.out.println("NameList after corrected spelling: " + NameList); //Uncomment when you are ready to test Part e
}
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images