Question: Problem 1-Fix code Submit a working program called: FilePractice.java. You will need to use the weather1.txt file to check if the program works properly (sample

Problem 1-Fix code Submit a working program called: FilePractice.java. You will

need to use the weather1.txt file to check if the program works properly (sample

run follows) but do not need to include it when turning in your assignment.

public class FilePractice

{

public static String[][] genFile()

{

Scanner in=new Scanner(System.in);

System.out.println("Enter file name:");

String fileName=in.nextLine();

/*Create an ArrayList of Strings from the file name entered*/

ArrayList allLines=;

/*Create a 2D array the that will hold all the information.*/

String[][] result = new String[4][];

/*This loop should run and capture all of the data*/

int i=2;

while (i < allLines.size())

{

/*Each line of the file should be put into the 2D array result*/

result[i] = get(i).split(",");

}

return result;

}

public static ArrayList readFile(String filename)

{

File temp = new File(filename);

/*Create a Scanner object to read in our file*/

Scanner iFile=new Scanner(temp);

ArrayList result = new ArrayList<>();

int i=0;

/*Keep reading in each line of the file into the ArrayList*/

while(iFile.hasNextLine()==1)

{

/*Add each line to the ArrayList*/

result[i].add(iFile.nextLine());

}

iFile.close();

return result;

}

public static void main(String[]args)

{

String [][] g=genFile();

System.out.println(" Second row:");

/*Print out the second row with info in the file*/

for(int i=0;i

{

System.out.printf("%s ",);

}

/*Print out Fri 4/3/2015 (do not hardcode)*/

System.out.println(" Date: "+);

}

}

Sample Run:

Enter file name:

weather1.txt

Second row:

Sun 3/8/2015 51 46 0.23

Date: Fri

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!