Question
Could you help me keep working my java homework called lab#6 ? Following the instructions with the the comments in the code. Thanks! import java.util.ArrayList;
Could you help me keep working my java homework called lab#6 ? Following the instructions with the the comments in the code. Thanks!
import java.util.ArrayList;
import java.util.Scanner;
import java.io.*;
//Functinality associated with a CSV file
// CSV ? Comma Separated Value, convention for
//exporting a spreadsheet or a DB into a text file.
public class CSV {
final static String NULL_STRING = "";
static int numFiles = 0;//tracks the number of CSV object created
// 5 instance variables of object
String fileName;
int fileNumber;
Scanner csvFile;
String curLine;
ArrayList
/*
*In practice we would expect to read the next line from
*the CSV file, but this is useful in testing
*/
public void setLine(String line_) {
this.curLine = line_;
} //setLine()
/*
* Read next line from CSV file
*/
public String getLine() {
this.curLine = this.csvFile.nextLine();
return this.curLine;
} //getLine()
public boolean eof() {
return !this.csvFile.hasNext();
} //eof()
public void close() {
this.csvFile.close();
} //close()
/*
* Parses this.curLines into a vector of
* comma delimited fields.
*
*/
public ArrayList
this.curFields.clear();
//add logic for lab #6 to do the actual parsing into this.curFields
// from this.curLine
return this.curFields;
} //parseFields()
public String toString() {
String description = NULL_STRING;
description = String.format("File name: \"%s\" ",this.fileName);
description = String.format("%sCurrent line: \"%s\" ",
description,this.curLine);
//For lab #6, Replace below with logic to print out a numbered list of the fields in curFields
description = String.format("%sField outputs to come! ",description);
return description;
} //toString()
/*
* Useful construtcor for testing
*/
public CSV () {
this.fileName = "UNOPENED";
this.curLine = NULL_STRING;
this.curFields = new ArrayList
} //useful testing constructor
/*
* In practice, we would typically want to construct
* a CSV object by opening a file
*/
public CSV(String fileName_) throws IOException {
this.fileName = fileName_;
this.csvFile = newScanner(new FileInputStream(this.fileName));
//set fileNumber and increment static class variable
this.fileNumber = CSV.numFiles++;
this.curLine = NULL_STRING;
this.curFields = new ArrayList
} //practical CSV constructor
public static void main(String []args) throws IOException {
CSV csv = new CSV();
//test with line from Johns Hopkins DB
csv.setLine("San Francisco,California,US,2020-04-13 23:07:54," +
"37.75215114,-122.43856720000001,957,15,0,942");
csv.parseFields();//does nothing until you add the needed logic
//calls toString to output a "useful" textual representation of the the object,
// as defined by the programmer.The 2nd part of your lab is to finish up toString()
System.out.println(csv);
//possible output:
//1. San Francisco
//2. California
//3. US
//4. 2020-04-13 23:07:54
//5. 37.75215114
//6. -122.43856720000001,
//7. 957
//8. 15
//9. 0
//10. 942
//below is not neeed for lab #6, it's just FYI to show where we're headed.
csv = new CSV("04-13-2020.csv");
for (int idx = 0; idx
if (csv.eof()){break;}
System.out.printf("%d%s ",idx,csv.getLine());
} //for
csv.close();
System.out.println(" *** CSV test suite complete ***");
} //main()
} //class CSV
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