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
/*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
{
File temp = new File(filename);
/*Create a Scanner object to read in our file*/
Scanner iFile=new Scanner(temp);
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started