Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Worksheet #6: CSV Data CSC 142 Computer Programming II Due Friday 2/24/2017 Info

ID: 3797805 • Letter: W

Question

Worksheet #6: CSV Data CSC 142 Computer Programming II Due Friday 2/24/2017 Information About Worksheet For this assignment, you will select a CSV data set from the website Data gov, which provides government data. You will write a Java program to load, parse, and filter the data contained in the CSV file for that data set. Visit https://data.gov and scroll down to the "Browse Topics" part of the page. Pick a topic that is interesting to you. Once you click the topic, click the word "Data" in the menu at the top. You will see a list of data sets. Look for a data set that is in CSV format. Java Code for Parsing Data Your Java code should consist of a main method (also called the program driver. The driver will call several static methods that will open the CSV data file, parse a single column from the data contained in the file, and print that column to a new file. Implement a static method copycolumn (string out, int n) that will read data from column n in the CSV data file, and write it out to a new file whose name is contained in the variable out Implement a static method fi ltercolumn (string out, int n that will read data from column n in the CSV data file, filter the data based on a criteria passed as the third argument (see below), and write the data to a new file whose name is contained in the variable out. The third argument will depend on the type of data you are filtering: If your columns contain numerical data, pass a double parameter called "max" and have your method only copy values from the column that are less than the maximum. If your columns contain labels or String data, pass a String parameter called "matchThis" and have your method only copy values from the column that contain the String match This. Instructions Complete a cover page in a word processor that answers the two questions above. Attach any Java code that you wrote to answer the questions, and submit these using the Worksheet 6 assignment on Canvas.

Explanation / Answer

import java.io.BufferedReader;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;

public class CSVReader {

    public static void main(String[] args) {

        String csvFile = "/Users/mkyong/csv/country.csv";

        BufferedReader br = null;

        String line = "";

        String cvsSplitBy = ",";

        try {

            br = new BufferedReader(new FileReader(csvFile));

            while ((line = br.readLine()) != null) {

                String[] country = line.split(cvsSplitBy);

                System.out.println("Country [code= " + country[4] + " , name=" + country[5] + "]");

            }

        } catch (FileNotFoundException e) {

            e.printStackTrace();

        } catch (IOException e) {

            e.printStackTrace();

        } finally {

            if (br != null) {

                try {

                    br.close();

                } catch (IOException e) {

                    e.printStackTrace();

                }

            }

        }

    }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote