Problem

Improve the CityTravel program code by prompting the user to enter origin and destination...

Improve the CityTravel program code by prompting the user to enter origin and destination cities and using the user-entered values in the

getDistance
method call. If the user does not spell one of the enumerated cities correctly, print an error message and loop until one of the enumerated cities is entered correctly. To get you started, here is the modified
main
method:

public static void main(String[] args){   final double KM_TO_MILES = 0.62137; // conversion factor   City origin = getCity("origin");   City destination = getCity("destination");   double distance = origin.getDistance(destination); // in km   System.out.printf("%s to %s: %.1f km, or %.1f miles",      origin, destination, distance, distance * KM_TO_MILES);} // end main

And here is an example of a typical sample session:

Enter origin city(PARKVILLE, HAVANA, KINGSTON, NASSAU, or SAINT_THOMAS): parkvilleInvalid entry. Must use exact spelling.Enter origin city(PARKVILLE, HAVANA, KINGSTON, NASSAU, or SAINT_THOMAS): PARKVILLEEnter destination city(PARKVILLE, HAVANA, KINGSTON, NASSAU, or SAINT_THOMAS): SAINT_THOMASPARKVILLE to SAINT_THOMAS: 3689.9 km, or 2292.8 miles

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT