Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java. I\'m getting ït\'s not possible\" for every airport search. Not sure what\

ID: 3729089 • Letter: J

Question

Java. I'm getting ït's not possible" for every airport search. Not sure what's wrong:

---------prompt-----------

The file is a csv file that contains many rows of three elements (airline code, from airport, and to airport). For this program only the airports are important. The airline code can be ignored.

After the graph is loaded, you will accept input from the console that will consist of two airport codes. Your program will determine only if it is possible to get from the one airport to the other. We will use this program as the base for the next exercise. Your program will generate a response that is either that it is or is not possible.

-----------Routes.csv(exerpt)----------

-----------java-------------

package p7;

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

import java.text.ParseException;

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

public class p7 {

public static void main(String[] args) throws ParseException, IOException {

      

   Scanner travelScanner = null;

   BufferedReader br = null;

      

   try{

          

       br = new BufferedReader(new FileReader("Routes.csv"));

       String line = null;

          

       List<String> airportList = new ArrayList<String>();

          

       while ((line = br.readLine()) != null){

           String str[] = line.split(",");

              

           for (int i = 0; i < str.length; i++){

               airportList.add(str[1] + "," + str[2]);

           }

       }

          

       System.out.println("So you're planning a trip? Let's see your options!");

       System.out.println(" For example, if your're going from LA to Vegas, you would just enter (LAX, LAS)");

       System.out.println(" Let's begin!");

          

       travelScanner = new Scanner(System.in);

       String travel = travelScanner.nextLine();

       String str[] = travel.split(",");

       if (airportList.contains(travel)) {

           //is possible

           System.out.println("YES! We can tak you from " + str[0] + " to" + str[1] + ".");

           //is NOT possible

       }else{

           System.out.println("We're sorry! It's NOT possible to travel from " + str[0] + " to" + str[1] + ".");

       }

       }catch(Exception exception){

           exception.printStackTrace();

       }

}

}

2B AER KZN 2B ASF KZN 2B ASF MRV 2B CEK KZN 2B CEK OVB 2B DME KZN 2B DME NBC 2B DME TGK 2B DME UUA 2B EGO KGD 2B EGO KZN 2B GYD NBC 2B KGD EGO 2B KZN AER 2B KZN ASF 2B KZN CEK 2B KZN DME 2B KZN EGO 2B KZN LED 2B KZN SVX 2B LED KZN 2B LED NBC 2B LED UUA 2B MRV ASF 2B NBC DME 2B NBC GYD

Explanation / Answer

package p7;

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

import java.text.ParseException;

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

public class p7 {

public static void main(String[] args) throws ParseException, IOException {

      

   Scanner travelScanner = null;

   BufferedReader br = null;

      

   try{

          

       br = new BufferedReader(new FileReader("Routes.csv"));

       String line = null;

          

       List<String> airportList = new ArrayList<String>();

          

       while ((line = br.readLine()) != null){

           String str[] = line.split(",");

              

           for (int i = 0; i < str.length; i++){

               airportList.add(str[1].trim()+ "," + str[2].trim()); // here the changes .. the list is taking space with

// words also. So trim will handle it.....

           }

       }

          

       System.out.println("So you're planning a trip? Let's see your options!");

       System.out.println(" For example, if your're going from LA to Vegas, you would just enter (LAX, LAS)");

       System.out.println(" Let's begin!");

          

       travelScanner = new Scanner(System.in);

       String travel = travelScanner.nextLine();

       String str[] = travel.split(",");

       if (airportList.contains(travel)) {

           //is possible

           System.out.println("YES! We can tak you from " + str[0] + " to" + str[1] + ".");

           //is NOT possible

       }else{

           System.out.println("We're sorry! It's NOT possible to travel from " + str[0] + " to" + str[1] + ".");

       }

       }catch(Exception exception){

           exception.printStackTrace();

       }

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote