Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 curFields;

/*

*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 parseFields() {

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

image text in transcribed
FIPS Admin2 Province_Country_R Last_UpdoLat Long_ Confirmed Deaths Recovered Active Combined_Key 45001 Abbeville South CareUS HHHHHH 34.223334 -82.46171 9 0 9 Abbeville, South Caro 22001 Acadia Louisiana US FHHHHHH 30.295065 -92.4142 101 51001 Accomack Virginia US 37.767072 -75.63235 15 UI 96 Acadia, Louisiana, US 15 Accomack, Virginia, U 16001 Ada Idaho US 43.452658 -116.2416 517 511 Ada, Idaho, US 19001 Adair Iowa US 41.330756 -94.47106 1 Adair, Iowa, US 21001 Adair Kentucky US 37.104598 -85.2813 11 11 Adair, Kentucky, US 29001 Adair Missouri US ####AT 40.190586 -92.60078 11 o O a O 0 11 Adair, Missouri, US 40001 Adair Oklahoma US ## # # # #t 35.884942 -94.65859 27 2 o o o O O O O 25 Adair, Oklahoma, US 8001 Adams Colorado US 39.874321 -104.3363 693 26 667 Adams, Colorado, US 16003 Adams Idaho US 1###### 44.893336 -116.4545 1 O O 1 Adams, Idaho, US

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

Students also viewed these Programming questions