Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

what is the the securities issuing process

Answered: 1 week ago

Question

What is operatiing system?

Answered: 1 week ago