/* cd ~/bin pwd ls -l CSV1.java javac CSV1.java echo $? ls -l CSV1.class wget -q -O - http://oit2.scps.nyu.edu/~meretzkm/pandas/teaser/yob2018.txt | java CSV1 */ import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class CSV1 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); scanner.useDelimiter(",\n"); //List is an interface, ArrayList is a class that implements it. List list = new ArrayList(); while (scanner.hasNextLine()) { String line = scanner.nextLine(); String[] field = line.split(","); boolean sex = field[1].equals("M"); //Don't use == int births = Integer.parseInt(field[2]); Name name = new Name(field[0], sex, births); list.add(name); } scanner.close(); for (Name name: list) { System.out.println(name); } System.exit(0); } } class Name { private String name; private boolean sex; private int births; public Name(String name, boolean sex, int births) { this.name = name; this.sex = sex; this.births = births; } @Override public String toString() { return name + " " + (sex ? "M" : "F") + " " + births; } }