45 lines
1.3 KiB
Java
45 lines
1.3 KiB
Java
import java.util.ArrayList;
|
|
import java.util.Scanner;
|
|
import java.io.FileInputStream;
|
|
import java.io.IOException;
|
|
|
|
public class StockDatabase {
|
|
private ArrayList<StockEntry> database;
|
|
|
|
public StockDatabase() {
|
|
database = new ArrayList<StockEntry>();
|
|
}
|
|
|
|
public ArrayList<StockEntry> 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);
|
|
}
|
|
|
|
}
|
|
}
|