Lecture 16 (Tychonievich) - CSV

Lecture Date: Wednesday, February 18

Q & A:

Grading:

  • If you pass all tests and don’t have horrible code, 10/10
  • If you don’t pass all tests, TAs assign a grade
  • Late:
    • Only look at last submission
    • If it is n days late and scored x/10, you get (x-n)/10

Why a 4-hour delay?

  • Try to break your own code
  • Comments and variable names so you remember what it was doing

How to make larger programs

  • By making smaller programs first
  • e.g., to find the power-of-two in Nim is tricky,
    • to find a power-of-two in a throw-away main method less so
    • once throw-away main method works, put into Nim

CSV

One common family of files is spreadsheets. The simplest format for spreadsheets is the “Comma Separated Value” or CSV. The idea is that each row is its own line and each cell of each row is separated by some character, such as a comma or semicolon.

We can get a row at a time using ourScanner.nextLine(). To get the cells in the row, we use the String method line.split(';') which splits a line around the given character (in this example, around ;s), returning an array of Strings (that is, a String[]).

We’ll talk about header rows, looking up rows by a particular cell, and begin to explore other ways of processing CSV files.

Data files:

Also, I’ll use a helper class CachingURL.java instead of a simple URL to reduce network traffic when we are all trying to access that same page at once.

From Lecture:

Audio: