# Two-Dimensional Array Example

Write a Java program that stores the names of two cites in a single dimension array, and their latitude and longitude in a two-dimension array. Next calculate the distance between the city in miles and display.

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):

The city names should be stored in a single dimension array that stores strings, and the latitudes and longitudes for each city should be stored as doubles in a two-dimension array.

Outputs: The distance between the two cities in miles, note: replace <> with the distance calculated

The distance between the two cities is <> miles

Code the program in Eclipse to prompt for the two cites and their latitudes / longitudes. Next, use the calcDistance method provided on page 2 to compute the distance between the two cities in miles. The method calcDistance will return a double value equal to the distance between the cities.

The distance in miles must be formatted and displayed to two decimal places in the main method using the printf command.

The names of the two cities must be stored as String variables in a single-dimension array, and the latitudes / longitudes of the two cities must be stored as double variables in a two-dimension array.

Use this method to calculate the distance in miles. You will pass the two-dimension array that stores latitudes / longitudes to the calcDistance method, and the method will return a double.

public static double calcDistance (double [][] list) {

// compute the distance

double xValue = (list[0][1] - list[1][1])*55;

double yValue = (list[0][0] - list[1][0])*69;

double distance = [login to view URL](xValue*xValue + yValue*yValue);

return distance;

}

Information on how calcDistance calculates the distance in miles.

The math formula for the distance between two points is:

(x2, y2)

distance= âˆš(ã€–(x2-x1)ã€—^2+ã€–(y2-y1)ã€—^2 )

(x1, y1)

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

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: [login to view URL] returns a double value.

distance = [login to view URL](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.

Kemahiran: Java, Kejuruteraan Perisian, JavaScript, PHP, Pengaturcaraan C

Tentang Majikan:
( 0 ulasan ) Mathews, United States

ID Projek: #29901029

surajnai567

hi there i can create a java program to calculate distance between two city. i have work experience in location based service. contact me we will discuss more in chat thank you.

\$25 USD dalam sehari
(4 Ulasan)
2.7

## 5 pekerja bebas membida secara purata \$25 untuk pekerjaan ini

devvitaliy

Hello JAVA EXPERT I have read your description and I am so interested in your project. You can see well experienced and skillful Java +15 years of experience in software development. Confident in your project and I can Lagi

\$30 USD dalam sehari
(58 Ulasan)
5.6
sheikhnazeer3

Hello, I read your job offer regarding the JAVA and I'm ready to start right away. I am also flexible with whatever budget you have. Accuracy and client's satisfaction is the top priority. Awaiting your response. T Lagi

\$19 USD dalam sehari
(29 Ulasan)
4.8
Martica199005

Hi, my name is Marta. I am quite new here but I've a 2 years of experience as developer, you can see some of my projects in my portfolio. I've already made project with Java and I am able to do a project like yours. I Lagi

\$30 USD dalam 7 hari
(2 Ulasan)
1.6
unholyhoper

Hello, I'm a java software developer at VERMEG, I have a ton of experience with Java I can help you make a program that calculates the distance between two locations. Thank you

\$20 USD dalam 7 hari
(0 Ulasan)
0.0