Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I write a Java program that calculates the distance between two points on earth?
    primarykey
    data
    text
    <p>I know how to start it out and I know how to put in the scanners and everything, but in school, I've never really learned about longitude and latitude formulas and how to convert those points into radians. So I'm pretty much stuck on this Java problem. Here is what I have so far:</p> <pre><code>import java.util.*; class DistanceCalculator { // Radius of the earth in km; this is the class constant. public static final double Radius = 6372.795; /** * This program computes the spherical distance between two points on the surface of the Earth. */ public static void main(String[] args) { Scanner console = new Scanner(System.in); intro(); System.out.print("Longitude (degrees.minutes) "); double Longitude = console.nextDouble(); System.out.print("Latitude (degrees.minutes) "); double Latitude = console.nextDouble(); } public static double distFrom(double lat1, double lng1, double lat2, double lng2); double Latitude = Math.toRadians(...); } public static void intro() { System.out.println("This program computes the spherical distance between two points on the surface of the Earth."); System.out.println("\tPlease start by entering the longitude and the latitude of location 1."); } } </code></pre> <p>In Java IDE, they say that Longitude and Latitude points (the ones underneath the <code>intro();</code>) are not used, and I know why, since I haven't really defined them yet. I know I'm missing the formula for longitude and latitude. In my book, it wants me to use the spherical law of cosines, and since I've never learned this at school, no matter how hard I study the formula from the websites I sought out, I don't know how to transfer that into Java language.<br> Another problem is, how do I transfer degrees and minutes from a longitude/latitude point into radians? Do I have to use <code>Math.toRadians</code> thing? Oh yeah and also, my answer has to be in kilometers.</p> <p>Updated: The math functions some of you guys are talking about confuses me greatly. In school (I'm a high schooler), even at Math IB SL, my teacher has never taught us how to find long/lat. points...yet. So it's hard for me to grasp. Since the spherical law of cosines formula is online, do I basically just take that formula and convert it into "java language" and plug it into my program?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload