Improve the CityTravel program code by prompting the user to enter origin and destination cities and using the user-entered values in the
getDistancemethod 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
mainmethod:
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 mainAnd 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
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.