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");
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
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
Get step-by-step solutions from verified subject matter experts

