Hey guys im dealing with a bit of an issue in my code and i would really appreciate some help.So i need to write a code that will read in some coordinates from a txt file and store them in an array (one 2d array or two 1d arrays),and then i need with a help from a function to calculate the maximum distance between all the coordinates that i have read in from the txt file.( exactly 30 pairs). Now i have read in those coordinates and i have made a function that does the math but in order for that function to work i need 4 arguments,and i have only 2. I'll put my code here so maybe some of u guys have an idea what im doing wrong or how i could get the extra 2 arguments i need. Thanks!
public class gps { public static double calculateDistance(double latitude1, double longitude1, double latitude2, double longitude2) { double deltaLatitude = Math.toRadians(latitude2 - latitude1); double deltaLongitude = Math.toRadians(longitude2 - longitude1); double a = Math.sin(deltaLatitude / 2) * Math.sin(deltaLatitude / 2) + Math.cos(Math.toRadians(latitude1)) * Math.cos(Math.toRadians(latitude2)) * Math.sin(deltaLongitude / 2) * Math.sin(deltaLongitude / 2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); return 6371000 * c; } public static void main(String [] args){ In.open("coordinates.txt"); String [] zeilen = new String [30]; String line; int i = 0; while(i < zeilen.length && (line =In.readLine ()) != null){ zeilen[i] = line; i++; } double [] x = new double [zeilen.length]; double [] y = new double [zeilen.length]; for( i = 0; i<zeilen.length; i++){ String s = zeilen[i]; String [] coords = s.split ("\\s+"); String number1 = coords [0]; String number2 = coords [1]; x[i] = Double.parseDouble(number1); y[i] = Double.parseDouble(number2); Out.println(x[i]); } In.close (); } }