import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.io.IOException;
import java.util.ArrayList;


public class CSVExporter {
  
  public static void main(String[] args) throws IOException {  
    
    // create some student records here; in TRW, these records 
    // could come from a database access (and SQL search)
    
    ArrayList<Student> students = new ArrayList<Student>();
    // note - the 'f' at the end of each GPA value stands for 'float'
    students.add(new Student("Sally Whittaker",2018,"McCarren House",312,3.75f));
    students.add(new Student("Belinda Jameson",2017,"Cushing House",148,3.52f));
    students.add(new Student("Jeff Smith",2018,"Prescott House",176,3.20f));
    students.add(new Student("Sandy Allen",2019,"Oliver House",108,3.48f));
    
    
    
    File f = new File("C:\\temp\\students.csv");// or "C:/temp/students.csv"
    FileOutputStream fout = new FileOutputStream(f);
    PrintStream out = new PrintStream(fout);   
    
    // Exercise: add an out.println() call below, to specify column names
    // for our CSV, eg. Name, GradYear, Dorm, Room, GPA
    // out.println(); // uncomment and fill in (or vice versa :))

    // loop through the 'students' list, output each element ("record") as CSV
    for(int i=0; i<students.size(); i++) {
      Student s = students.get(i);
      out.println(s.name+","+s.gradYear+","+s.dorm+","+s.room+","+s.GPA);
    }// next student
    

    
    // done, close
    out.close();
  }// main()
  
}// class CSVExporter


