Two-Dimensional Array Example

Përfunduar Postuar 3 vite mё parё Paguhet në dorëzim
Përfunduar Paguhet në dorëzim

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.

Java Arkitekturë softuerësh JavaScript PHP Programim C

ID Projekti: #29901029

Rreth projektit

5 propozimet Projekti në distancë Aktiv 3 vite mё parё

Është zgjedhur fitues:

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 për 1 ditë
(4 Përshtypje)
2.7

5 profesionistë freelancer dërguan një ofertë mesatare prej $25 për këtë punë

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 Më shumë

$30 USD për 1 ditë
(58 Përshtypje)
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 Më shumë

$19 USD për 1 ditë
(29 Përshtypje)
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 Më shumë

$30 USD për 7 ditë
(2 Përshtypje)
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 për 7 ditë
(0 Përshtypje)
0.0