Question
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:
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.
(x2, y2) distance= (x2-x1)2+(y2-y1)2 (xl, y1) difference inlongitude (x) difference inlatitude (y) Problems @ JavadocDeclaration Console 3Data Hierarchy
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started