1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
posledela
3 years ago
5

Write a program to calculate the great circle distance between two points on the surface of a sphere. If p1(x1, y1) and p2(x2,y2

) are geographic latitude and longitude of two points, the great circle distance can be computed as
Computers and Technology
1 answer:
Tamiku [17]3 years ago
8 0

Answer:

import java.lang.*;

public class distance { public static double distance(double latitude1,

                                     double latitude2, double longitude1,

                                     double longitude2)

       {

      // Convert Latitude and Longitude to Radians

           longitude1 = Math.toRadians(longitude1);

           longitude2 = Math.toRadians(longitude2);

           latitude1 = Math.toRadians(latitude1);

           latitude2 = Math.toRadians(latitude2);

           

           double d_longitude = longitude2 - longitude1;

           double d_latitude = latitude2 - latitude1;

           double a = Math.pow(Math.sin(d_latitude / 2), 2)

                   + Math.cos(latitude1) * Math.cos(latitude2)

                   * Math.pow(Math.sin(d_longitude / 2),2);

           double val = 2 * Math.asin(Math.sqrt(a));

           // Radius of earth in kilometers is 6371

           double earth_radius = 6371;

           // Calculate and return the distance

           return(val * earth_radius);

       }

       // Main Method

       public static void main(String[] args)

       {

           double latitude1 = 67.32055555555556;

           double latitude2 = 83.31861111111111;

           double longitude1 = -1.7217899;

           double longitude2 = -1.6567799;

           System.out.println(distance(latitude1, latitude2,

                   longitude1, longitude2) + " K.M");

       }

   }

Explanation:

This program is implemented in Java programming language

The formula for the shortest distance between two points on the earth is:

Distance = 3963.0 * arccos[(sin(lat1) * sin(lat2)) + cos(lat1) * cos(lat2) * cos(long2 – long1)]

The latitude and longitude of the two points must be known

The latitude and longitude are converted into radians using built in methods in java.

Take value for the radius of the earth in Kilometers  6371;

Note that a seperate method has been created to calculate the distance

In the driver method (main), values for latitude and logitudes for both places have been hard-corded, then the method distance is called and passed those values

Note also that the distance has been calculated in Kilometers

You might be interested in
Clifford created a table using OpenOffice Writer and entered some information into the table. Later, he needed to add more rows
Minchanka [31]

Right click the cell, click add cells & it should say the options (new row above etc.)

4 0
3 years ago
Read 2 more answers
In Java please:Re-type the code and fix any errors. The code should convert non-positive numbers to 1. if (userNum > 0) Syste
iren2701 [21]

Answer:

import java.util.Scanner;

public class Solution {

   public static void main(String args[]) {

       Scanner scan = new Scanner(System.in);

       int userNum = scan.nextInt();

       if (userNum > 0) {

           System.out.println("Positive.");

           

       } else {

           System.out.println("Non-positive, converting to 1.");

           userNum = 1;

           System.out.println("Final: " + userNum);

           

       }

   }

}

Explanation:

There was no error found when the code was run. The code segment was just added to a main method and it runs successfully.

Based on the full code above;

The first line import the Scanner class which allow the program to receive user input. Then the class was defined as Solution. Then the main method was defined. Inside the main method, we created a scanner object scan which receive the input via keyboard. The user input is assigned to the variable userNum. Then the if-conditional statement is executed; if userNum is greater than 0, "Positive" is output. Else userNum is converted to 1 and outputted to the screen.

8 0
4 years ago
What is the output?
goldenfox [79]

Answer:

7.0

Explanation:

i got it wrong to get the answer

4 0
3 years ago
Read 2 more answers
I don’t understand this, i need help
Fittoniya [83]

Answer:

I don't understand this either sorry

Explanation:

5 0
3 years ago
Which statement is false? Select one: a. A class is to an object as a blueprint is to a house. b. Classes are reusable software
kow [346]

Answer:

A class is an instance of its object

Explanation:

6 0
3 years ago
Other questions:
  • A video conferencing application isn't working due to a Domain Name System (DNS) port error. Which record requires modification
    15·1 answer
  • 11. In Microsoft Word, when you highlight existing text you want to replace, you're in
    8·1 answer
  • Damian uses a modem to connect to a dial-up network. Which statements are true of a modem?
    11·2 answers
  • What is a complex instruction set computer chip? Multiple Choice Performs all arithmetic operations (for example, addition and s
    6·1 answer
  • 1.6.M - Assignment: Understanding If Else Statements in Python
    7·1 answer
  • Drag each tile to the correct box.
    7·2 answers
  • Write pseudocode for a function that translates a telephone number with letters in it (such as 1-800-FLOWERS) into the actual ph
    11·1 answer
  • Giusp minfg gấp vs ạ đáp án thôi nhé
    15·1 answer
  • C code
    6·1 answer
  • What is a use case of factorization in quantum computing?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!