Java Application - DistanceCalculator Solution

Java Application - DistanceCalculator

Create a Java application named to solve the following problem.

An application is needed to allow a user to enter two cities and display the distances between them.

A text file named CityDistances.txt contains the names of cities and the distances between each city. The file has the following contents (the text file is attached in the folder):

Notice that the file tokens are delimited by commas.
The first number in the file is the number of cities. The next lines contain the city names and the distances between cities that can be used to create a two dimension array to model the distance table shown on the previous page.

The application should read the cities into a one dimensional array and the distances into a two dimensional array.

After the arrays are created, display the number of cities and a list of cities and then prompt the user to enter two cities and then display the distances between the two cities. Validate the user input to not allow invalid cities to be entered. Create a loop to continue prompting until the user wants to exit the program.

Use fields to hold the city names array and the distances array.

Use modular programming. I suggest a method to load the arrays from the file, and a method to retrieve the city numbers and display the distance.

Program output might look like this:

Name the Java Class: DistanceCalculator1

Add descriptive comments throughout the program.

Powered by