Question: Improve the CityTravel program by prompting the user to enter origin and destination cities and using the user-entered values in the getDistance method call. If

Improve the CityTravel program 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. Do this by providing a new method with this signature:

public static City getCity(String originOrDestination)

And in the modified main method, replace:City origin = City.PARKVILLE;

City destination = City.KINGSTON; 

with this:

City origin = getCity("origin");

City destination = getCity("destination");

  1. Sample session: Enter origin city (PARKVILLE, HAVANA, KINGSTON, NASSAU, or SAINT THOMAS): Parkville Invalid

Sample session: Enter origin city (PARKVILLE, HAVANA, KINGSTON, NASSAU, or SAINT THOMAS): Parkville Invalid entry. Must use exact spelling. Enter origin city (PARKVILLE, HAVANA, KINGSTON, NASSAU, or SAINT THOMAS): PARKVILLE Enter destination city (PARKVILLE, HAVANA, KINGSTON, NASSAU, or SAINT_THOMAS): SAINT THOMAS PARKVILLE to SAINT THOMAS: 3689.9 km, or 2292.8 miles

Step by Step Solution

3.49 Rating (159 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Based on the description and sample session given you want to create a program that prompts the user for the origin and destination cities for travel ... View full answer

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 Introduction To Programming With Java A Problem Solving Approach Questions!