import java.util.ArrayList; import java.util.Scanner; import java.io.FileInputStream; import java.io.IOException; public class StockDatabase { private ArrayList database; public StockDatabase() { database = new ArrayList(); } public ArrayList getDatabase() { return database; } public void readStockData(String filename){ FileInputStream fileByteStream = null; Scanner scnr = null; try{ //open file & set delimeters fileByteStream = new FileInputStream(filename); scnr = new Scanner(fileByteStream); scnr.useDelimiter("[,\r\n]+"); scnr.nextLine(); while(scnr.hasNext()){ String date = scnr.next(); double open = scnr.nextDouble(); double high = scnr.nextDouble(); double low = scnr.nextDouble(); double close = scnr.nextDouble(); StockEntry s = new StockEntry( date, open, high, low, close); database.add(s); } fileByteStream.close(); } catch(IOException error1){ System.out.println("Error with file " + filename); } } }