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
Step: 1
Based on the provided code the class CSVREADER is designed to read a CSV file and store flight infor...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started