Question: Java: Write a program to allow a user to enter the name of a starting city and a destination city. Output the mileage between cities

Java: Write a program to allow a user to enter the name of a starting city and a destination city. Output the mileage between cities and an estimate of the total number of fuel stations on the way. The number of fuel stations between two cities is the sum of the number of fuel stations in the starting city and the number of fuel stations in the destination city, all divided by 4 (since many of the stations will likely not be on the road between the two cities).

Store the mileage between 8 different cities in a 2D array of integers. Choose names of cities in Texas. Store the number of fuel stations in each city in a 1D array.

Your program should first print a title showing the name of the program, version number and copyright notice with author name (insert your name as the author). Also, print a list of the cities in the database so the user knows what cities they can search.

Look up the mileage between the cities on the Internet and use the values you find in your program. You are free to create your own estimate of how many fuel stations are in each city.

For example, if Houston has 100 fuel stations and Beaumont has 20, then the output of your program should look something like:

City Mileage w/ Fuel Stations ver. 1.0 (C) 2017 First Last

The cities in the database are:

1. Dallas (85 stations)

2. Houston (100 stations)

3. Beaumont (20 stations)

4. Austin (75 stations)

5. El Paso (44 stations)

6. Lubbock (59 stations)

7. Texarkana (37 stations)

8. Corpus Christi (39 stations)

Enter the starting city: Beaumont

Enter the destination city: Houston

Mileage: 75 miles

Estimated # of fuel stations: 30

The pseudocode for this HW from our professor looks like this:

//Pseudocode for Homework 7 main () { String cities // 1D array of city names int stations // 1D array of # of stations int mileage // 2D array of mileage // reference slide 3 in chapter 8 String startCity, dstCity int estStations // # stations in (startCity + dstCity) / 4 Scanner input int startIndex, dstIndex // indeces corresponding to the city names create Scanner object print title, copyright notice.. print "The cities in the database are" for (int i=0; i<8; i++) println i+1 + cities[i] + "( " stations[i] + " stations)" print a blank line print "Enter the starting city" startCity = read from keyboard print "Enter the destination city" dstCity = read from keyboard // Calculate the index of the starting city for (startIndex=0; startIndex<8; startIndex++) if (startCity.equals(cities[startIndex])) break // Calculate the index of the destination city for (dstIndex=0; dstIndex<8; dstIndex++) if (dstCity.equals(cities[dstIndex])) break println "Mileage " + mileage[startIndex][dstIndex] + " miles" estStations = (stations[startIndex] + stations[dstIndex]) / 4 print "Estimated number....:" + estStations } // Example creating a 1D array of Strings static String [] cities = { "Dallas", "Houston", ... }; 

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!