Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Chapter 4 Project Project Name: Chpt4_Project Class Name: Chpt4_Project Write a Java program that accepts the coordinates of two cities, and outputs the distance between

Chapter 4 Project

Project Name: Chpt4_Project

Class Name: Chpt4_Project

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, note: replace with the distance calculated

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 and display the distance between the two cities in miles. The distance in miles must be formatted to two decimal places using the printf command.

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

The math formula for the distance between two points is:

image text in transcribed

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

y = (lat1 lat2) * 69;

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

x = (long1 long2) * 55;

Once you have calculated the x and y values, which are in miles, use this Java formula to calculate distance in miles. Note: Math.sqrt returns a double value.

distance = Math.sqrt(x*x + y*y);

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.

image text in transcribed

(x2, y2) distance= (x2-x1)2+(y2-y1)2 (xl, y1) difference inlongitude (x) difference inlatitude (y) Problems @ JavadocDeclaration Console 3Data Hierarchy C4 Project [Java Application) C:AProgram FilesUavajre1.8.0 1441binliaww.&oct 18, 2017,3:25:48 PM) Enter the first city: orlando Enter the second city: Tampa Enter latitude and longitude of first city separated ce (example 28.8 81.2): 28.5 -81.4 space (example 28.8 81.2): 27.9 -82.5 he distance between the two cities is 73.31 miles

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Temple Of Django Database Performance

Authors: Andrew Brookins

1st Edition

1734303700, 978-1734303704

Students also viewed these Databases questions

Question

4. How do relations of power and dominance affect adaptation?

Answered: 1 week ago