2021年5月4日星期二

How do i instantiate the ArrayList and File objects in the constructor? [closed]

The DataReader class:

This class is responsible of reading the data from the CSV file and maintain a list of states to hold the data. It should contain 2 instance variables:

An ArrayList to store the State objects. A File object representing the file from which you will read the data. The DataReader class should contain a constructor that accepts one String parameter representing the file name. Inside the constructor, you need to instantiate your ArrayList and File objects. In addition, define a method called readData that accepts no parameters and returns an ArrayList object. Inside readData, you should write the code that reads the data from the CSV file. For each line in the file, define a State object and pass the information to the State constructor. Add each created State object to the ArrayList. Finally, the method returns a reference to the ArrayList holding the created State objects.

Above is part of a project im working on. This is what i have so far, im stuck on what to do next.

public class DataReader {

private String fileName;    DataReader(String fn) {      fileName = fn;  }        

}

https://stackoverflow.com/questions/67394634/how-do-i-instantiate-the-arraylist-and-file-objects-in-the-constructor May 05, 2021 at 11:00AM

没有评论:

发表评论