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 to follow. The next line is an integer representing the number of cities
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 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:
SanFrancisco
NewYork
LosAngeles
SanFrancisco LosAngeles
SanFrancisco NewYork
LosAngeles NewYork
Austin
Istanbul
Calcutta
NewYork
Enter filename: routes.txt
Route :
SanFrancisco LosAngeles NewYork
Route :
Austin NewYork London Istanbul Calcutta
Route :
Reykjavik Aarhus Budapest Geneva
Run again YN: n
COSC S
London
Austin Istanbul
Austin Calcutta
Austin NewYork
Austin London
Istanbul Calcutta
Istanbul NewYork
Istanbul London
Calcutta NewYork
Calcutta London
NewYork London
Reykjavik
Aarhus
Geneva
Budapest
Reykjavik Aarhus
Reykjavik Geneva
Reykjavik Budapest
Aarhus Budapest
Geneva Budapest
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
