Question: in JAVA Write a program that takes a list of cities to visit and outputs all the visited cities in the shortest distance possible by

in JAVA Write a program that takes a list of cities to visit and outputs all the visited cities in the shortest
distance possible by air. Input is from a data file where the first integer represents the number of data
sets in the range [1,15] to follow. The next line is an integer representing the number of cities [2,100]
to visit on the trip, followed by a list of cities, each on one line and containing no spaces. The first city in
this list represents the city that one is currently in. The next line is an integer representing the number
of available flights. The following lines will be two cities, separated by a space, and an integer
representing the number of miles that flight covers. Assume the following:
There will always be a flight to the city one wants to visit.
If there is a flight from city A to city B assume the same flight from city B to city A exists.
If there is no flight listed between two cities, assume that a route does not exist between them.
There will be at least two cities to travel between.
There will always exist a route between any two cities, although it may take several hops. The
distance between any two adjacent cities will be greater than 1 mile.
The best solution will never require backtracking.
For each labeled data set, output to the screen the names of the visited cities in order by air in the least
amount of distance. One starts in the current city with each flight represented by a "=>" sign between
the cities. Let the user input the file name from the keyboard. Finally, the program should ask if the
user wants to run the program again (Check case). Use a graph data structure. Refer to the sample
output below.
Sample File: Sample Run:
3
3
SanFrancisco
NewYork
LosAngeles
3
SanFrancisco LosAngeles 383
SanFrancisco NewYork 2905
LosAngeles NewYork 2789
5
Austin
Istanbul
Calcutta
NewYork
Enter filename: routes.txt
Route 1:
SanFrancisco => LosAngeles => NewYork
Route 2:
Austin => NewYork => London => Istanbul => Calcutta
Route 3:
Reykjavik => Aarhus => Budapest => Geneva
Run again (Y/N): n
COSC 2436 S24
3
London
10
Austin Istanbul 6500
Austin Calcutta 8773
Austin NewYork 1513
Austin London 4921
Istanbul Calcutta 3652
Istanbul NewYork 5020
Istanbul London 1556
Calcutta NewYork 7929
Calcutta London 4853
NewYork London 3465
4
Reykjavik
Aarhus
Geneva
Budapest
5
Reykjavik Aarhus 1515
Reykjavik Geneva 2379
Reykjavik Budapest 2443
Aarhus Budapest 933
Geneva Budapest 787
Name the program: CityOrderXX.java or CityOrderXX.cpp, where XX are your initials.

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 Programming Questions!