Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

Based on the provided code the class CSVREADER is designed to read a CSV file and store flight infor... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions