Question: *Edit: Please provide the coords.txt file. Are we not creating the file oursleves. The goal of this program is to create the file using the

*Edit: "Please provide the coords.txt file". Are we not creating the file oursleves. The goal of this program is to create the file using the PrintWriter method, correct??

Hello, I was wondering if I could get help of completing this program. I've been having a hard timing trying to understand and how your suppose to approach this problem. I would appreicate if you explaing how you approached this. Thank You.

Instructions

Write a program WriteCSV.java that reads in a text file line by line, replaces all spaces with commas, and writes new lines to a new CSV file.

This program contains a template from which you will begin coding. There is not a lot of code to write, but many things to practice.

Program Requirements

(1) Your task is to fix all the "TODO"s in the following code.

// TODO import statements public class WriteCSV { public static void main(String[] args) { // Grading program needs hardcoded filename. Oh, well. " String inputFilename = "coords.txt"; String outputFilename = changeFileExtToCsv(inputFilename); // Open files Scanner input = //TODO: call method to open input file PrintWriter output = //TODO: call method to open output file // TODO: Read input line, replace all spaces with commas, // and write output line while (input.hasNextLine()) { } // TODO: close streams } /** * Changes file extension to ".csv" * @param filename * @return */ public static String changeFileExtToCsv(String filename) { return filename.substring(0,filename.lastIndexOf('.')) + ".csv"; } /** * Open input for reading * @param filename * @return */ public static Scanner openInput(String filename) { Scanner in = null; // TODO: surround the next two lines with a try block File infile = new File(filename); in = new Scanner(infile); // TODO: surround the next two lines with a catch block System.out.println(filename + " could not be found"); System.exit(0); return in; } /** * Open output for writing * @param filename * @return */ public static PrintWriter openOutput(String filename) { //TODO: Write method to open a PrintWriter ; use openInput() as a guide } } 

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 Databases Questions!