Lengkap

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

Lihat lagi: example write check 200, dimensional array image, bitmap image dimensional array, give example write authorization letter, example write description products quality, example write 200 word article, example write employee month award special project, java dimensional array file gui example, two dimensional array in java example program, two dimensional array in c++, two dimensional array java for loop, how to assign values to two dimensional array in java, excel vba two dimensional array different data types, how to declare two dimensional array using pointers in c++, two dimensional array in c, two dimensional string array in c, two dimensional array c#, dynamic two dimensional array in c#, write a java program that takes two numbers as input and display the product of two numbers., find max value in two dimensional array javascript

Tentang Majikan:
( 0 ulasan ) Mathews, United States

ID Projek: #29901029

Dianugerahkan kepada:

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