Question: The objective of this program is to read from a text file into an ArrayList then use those elements to fill a two dimensional array.
The objective of this program is to read from a text file into an ArrayList then use those elements to fill a two dimensional array. Please fill in the tasks outlined in the comments (image of desired output is attached)------------------------------------------------------------------------------------------------------------------------------------ import java.io.*; import java.util.*; public class ReadFile { public static ArrayList readLineByLine(BufferedReader reader)throws IOException{ // create input String // create ArrayList // create a while loop that continues to add to the ArrayList from the reader as long as the input is not null // return the ArrayList } public static void writeToFile(String [][] wrestlers, String path)throws IOException{ // create a name of the output file, Ex/ "wrestlers.txt" // I am giving you the code to find the parent directory and the path of the new output file File file = new File(path); String parentDirectory = path.substring(0,file.getAbsolutePath().lastIndexOf(File.separator)); String newPath = parentDirectory + "/" + newFile; System.out.println("Written to: " + newPath); // create a BufferedWriter object to write to the newPath previously created // use a for loop to go through the 2D array and writes the name and the age to the file // close the BufferedWriter object } public static String[] convertToArray(ArrayList names){ // create a string array and allocate the size of the array with the size of the ArrayList // use a for loop to go through the ArrayList and populate the String array with the contents of the array list // return the String array } public static String[][] getAge(String[] actors){ // create a Scanner; // create a 2D String array with [length of actors][2] as dimesions of the array // use a for loop to go through the String array to populate the 2d String array // ask for the actor's age from the array (print out the name at the index x) // read the age as a string // write the name to the first element of the array at index x // write the age to the second element of the array at index x // return the 2D array } public static void main(String [] args)throws IOException{ // replace the path here with the correct path to the txt file given on blackboard String path = "/homeeil/Documents/object-oriented-programming/Tutorial 8/solutionames.txt"; try{ // create FileReader object that reads from path variable // create BufferedReader object that reads from FileReader object // pass the BufferedReader to the readLineByLine method to get an ArrayList back // pass ArrayList to convertToArraty method to get a single String array back // pass the String array to the getAge method to get the 2D String array back // pass the 2d String array to the writeToFile method to write the contents to file }catch(FileNotFoundException ex) { System.out.println( "Unable to open file '" + path + "'"); } } }
Conditions In this task, you are to read from a text file and use an array list to read data that you do not assume the size of before execution run: Enter the age of wrestler "Randy Savage" 954 Enter the age of wrestler "The Undertaker": 54 Enter the age of wrestler "Steve Austin": 65 enter the ap ct vroster som Cona 76 Writtern to: honeeil/Documents/object-oriented-programming/TutoriaL B/solution/wrestlers .tx
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts

------------------------------------------------------------------------------------------------------------------------------------ import java.io.*; import java.util.*; public class ReadFile { public static ArrayList readLineByLine(BufferedReader reader)throws IOException{ // create input String // create ArrayList // create a while loop that continues to add to the ArrayList from the reader as long as the input is not null // return the ArrayList } public static void writeToFile(String [][] wrestlers, String path)throws IOException{ // create a name of the output file, Ex/ "wrestlers.txt" // I am giving you the code to find the parent directory and the path of the new output file File file = new File(path); String parentDirectory = path.substring(0,file.getAbsolutePath().lastIndexOf(File.separator)); String newPath = parentDirectory + "/" + newFile; System.out.println("Written to: " + newPath); // create a BufferedWriter object to write to the newPath previously created // use a for loop to go through the 2D array and writes the name and the age to the file // close the BufferedWriter object } public static String[] convertToArray(ArrayList names){ // create a string array and allocate the size of the array with the size of the ArrayList // use a for loop to go through the ArrayList and populate the String array with the contents of the array list // return the String array } public static String[][] getAge(String[] actors){ // create a Scanner; // create a 2D String array with [length of actors][2] as dimesions of the array // use a for loop to go through the String array to populate the 2d String array // ask for the actor's age from the array (print out the name at the index x) // read the age as a string // write the name to the first element of the array at index x // write the age to the second element of the array at index x // return the 2D array } public static void main(String [] args)throws IOException{ // replace the path here with the correct path to the txt file given on blackboard String path = "/homeeil/Documents/object-oriented-programming/Tutorial 8/solutionames.txt"; try{ // create FileReader object that reads from path variable // create BufferedReader object that reads from FileReader object // pass the BufferedReader to the readLineByLine method to get an ArrayList back // pass ArrayList to convertToArraty method to get a single String array back // pass the String array to the getAge method to get the 2D String array back // pass the 2d String array to the writeToFile method to write the contents to file }catch(FileNotFoundException ex) { System.out.println( "Unable to open file '" + path + "'"); } } }