Question: Using Java I'm searching for possible routes between two airports. Where some of them should be possible I'm getting t's not possible for every airport

Using Java I'm searching for possible routes between two airports. Where some of them should "be possible" I'm getting t's not possible" for every airport search. Test data that should work

AER, KZN

SEA, PDX SAN. LAX

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

Write a program that will load a graph with the contents of the file Routes.csvUsing Java I'm searching for possible routes between two airports. Where some

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)----------

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

-----------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 airportList = new ArrayList();

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

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

for (int i = 0; i

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

}

}

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 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();

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!