I have a Java program I have written in Eclipse with the goal of taking data values stored in Excel and putting those into a correlation plot for hypothesis testing using the Nebula plug in. I am using buffered reader to import my data, and I have been able to get the data I want to return to the console using encapsulation and constructors. My question: is it possible/ practical to store this output into arrays so I can plot it? My thought is to initialize the arrays and then store the output via a method somehow, but I'm stuck on how to do it....
EDIT: I should clarify- I am asking about transferring my object into parallel arrays. Is this good practice or not? And if so, how can this be done most efficiently?
Some code (it's long, but I don;t want to leave anything critical out):
public class CovidPlots {
public static void main(String[] args) {
//Data source
List<Book> stocks = readBooksFromCSV("COVID_DJI.csv");
for (Book b : stocks) {
System.out.println(b);
}
private static List<Book> readBooksFromCSV(String fileName) {
List<Book> stocks = new ArrayList<>();
Path pathToFile = Paths.get("C:\\Users\\zrr81\\Downloads\\COVID-19_Analysis\\COVID_DJI.csv");
//Try/catch IO exception for input file stream
try (BufferedReader br = Files.newBufferedReader(pathToFile, StandardCharsets.US_ASCII)) {
//Initialize counter to skip header
int count = 0;
String line = br.readLine();
while(line != null) {
//Tell the reader to split the text when it hits the delimiter
String[] attributes = line.split(",");
Book book = createBook(attributes);
stocks.add(book);
count ++;
line = br.readLine();
}
}
catch (IOException e) {
e.printStackTrace();
}
return stocks;
}
//Create output arrays
String[] days;
double [] openers;
double[] closers;
//Import data into array "Book"
private static Book createBook(String[] metadata) {
String day = metadata[0];
double opener = Double.parseDouble(metadata[1]);
double closer = Double.parseDouble(metadata[4]);
return new Book(day, opener, closer);
}
}
//Book class file (separate file in my package)
class Book {
//Define spreadsheet "Book"
private String date;
private double opener;
private double closer;
// All-args constructor, getters, setters and toString()
// left out for brevity
}