Question: is this a good class scanner reader that reads any kind of file. It will store your flight information into a 1D array of Flight?

is this a good class scanner reader that reads any kind of file. It will store your flight information into a 1D array of Flight? how would i pass the name of the file from the main so it correctly makes the list?

public class CSVREADER{
String path;
Scanner in;
File fileObj;

int getFileSize(String s){
 int size;
 while(this.in.hasNextLine()){
  this.in.nextline();
  size++
 }
 return size
}

void csvReader(String path){
 this.path = path;
 this.fileObj = new File(path);
 this.in = new Scanner(fileObj);
}

 public Flight[] getFlights(String f) {
    ArrayList tempList = new ArrayList<>();
    while (in.hasNextLine()) {
     String line = in.nextLine();
     tempList.add(line);
    }
   String[] tempArray = tempList.toArray(new String[0]);
   Flight[] flightList = new Flight[tempArray.length];
   for (int i = 0; i < tempArray.length; i++) {
     flightList[i] = new Flight(tempArray[i]);
   }
   return flightList;
 }

}

 


Step by Step Solution

3.46 Rating (146 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Based on the provided code the class CSVREADER is designed to read a CSV file and store flight infor... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!