Write a program GreatCircle.java that takes four doubles x1, y1, x2, and y2 representing the latitude and longitude in degrees of two points on earth as command-line arguments and writes the great-circle distance (in km) between them, given by the equation
d = 111 arccos(sin(x1 ) sin(x2 ) + cos(x1 ) cos(x2 ) cos(y1 − y2 )).
//GreatCircle.java public class GreatCircle { public static void main(String[] args) { if(args.length==4){ int x1,y1,x2,y2; x1 = Integer.parseInt(args[0]); y1 = Integer.parseInt(args[1]); x2 = Integer.parseInt(args[2]); y2 = Integer.parseInt(args[3]); double d; d = 111 * Math.acos(Math.sin(x1) * Math.sin(x2) + Math.cos(x1) * Math.cos(x2) * Math.cos(y1 - y2 )); System.out.println("Distance ="+d); } else{ System.out.println("Please pass 4 command line arguments"); } } }
Get Answers For Free
Most questions answered within 1 hours.