Question: how do i properly make a method that takes in a 1d array and prints out the information in the 1d array that contains a

how do i properly make a method that takes in a 1d array and prints out the information in the 1d array that contains a name of a city, country, double oneWay, and double roundtrip.

This method receives all the Flights stored in a 1D array and displays them to the user.

 

public static void displayAvailableFlights(Flights[] f)throws Exception{

 System.out.println("--------------------------[ Available Flights ] --------------------------");
 System.out.println("| " + "CITY" + "t |   "  + "COUNTRY" + "t |   "+ "ONE WAY" + "t |   " + "ROUND TRIP" + " |");
 
 //Read file for variable info
 File myFile = new File("flights.csv");
 Scanner fileReader = new Scanner(myFile);
 while(fileReader.hasNextLine()){
  String city = fileReader.next();
  String country= fileReader.next();
  double oneWay = fileReader.nextDouble();
  double roundTrip = fileReader.nextDouble();

  //Print info
  System.out.println("|" +  city + "t" + country + "  | $" +  oneWay + "t| $ " + roundTrip + "t| ");
  System.out.println("----------------------------------------------------------------");
 }
}
 

 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The provided code seems to be mostly correct for reading flight information from a file and displayi... 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!