Question: Write a Java program that accepts the coordinates of two cities, and outputs the distance between them in miles. Inputs: The names of two cities

Write a Java program that accepts the coordinates of two cities, and outputs the distance between them in miles.

Inputs: The names of two cities and their latitudes and longitudes.

Enter the first city:Enter the second city:

Enter latitude and longitude of first city separated by a space (example 28.8 81.2):

Enter latitude and longitude of second city separated by a space (example 28.8 81.2):

Outputs: The distance between the two cities in miles

The distance between the two cities is <> miles

Step 1. Create an algorithm (either flowchart or pseudocode) that you will use to write the program. Place the algorithm in a Word document.

Step 2. Code the program in Eclipse to compute the distance between the two cities in miles.

Note: You can use Google Maps to get lat/long of a city. Right-click and choose whats here?

The math formula for the distance between two points: (x2, y2)

(x1, y1)

difference in longitude (x) difference in latitude (y)

The Java formula for distance is:

Distance = Math.sqrt(x*x + y*y)

To convert the difference in latitude to miles, multiply by 69

x = (lat1 - lat2) * 69;

To convert the difference in longitude to miles, multiply by 55

y = (long1 - long2) * 55;

Note: The distance in miles must be formatted to two decimal places using the printf command.

Step 3. Test your program by computing the distance between Orlando and Tampa. The latitudes and longitudes are provided below. Use the Snip It tool in Windows or a similar tool on the Mac to cut and paste the Eclipse Console output window into the same Word document as the algorithm in Step 1.

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!