Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

COMP163 Global Direction Program Write a program with a Graphical User Interface

ID: 3748685 • Letter: C

Question

COMP163 Global Direction Program Write a program with a Graphical User Interface (GUl) that will display the direction from Greensboro to any point on the globe. The direction can be calculated by atan2 ( sin(longitude- gboroLong) cosClatitude costgboroLat) * sin( latitude)-sin(gboroLat) cos latitudecost longitude gboroLong)) where lon gitudeis the longitude of the destination in radians latitudeis the latitude of the destination in radians gboroLongis the longitude of Greensboro in radians gboroLatis the latitude of Greensboro in radians Positive latitudes are north of the equator, negative latitudes are south. Positive longitudes are east of the zero meridian and negative longitudes are to the west. Note that atan2 is a method of the Math class that takes two parameters separated by a comma. The program should input the latitude and longitude of the destination as degrees and minutes. You will have to convert to radians using the equation minutesy radans (degres 60 180 180 Convert the calculated direction in radians to degrees by degrees radians Some interesting locations city latitudelongitude deg, min deg, min Greensboro San Francisco377-122 -47 London Paris Mecca Perth Mumbai 51 30 -0-7 2 21 39 48 21 25 31-57115 51 191 7251

Explanation / Answer

import java.io.*;

import java.lang.Math;

public class Direction

{

private int longitude[]=new int [2]; // Array to store degrees in 0th Index and minutes in 1st Index

private int latitude[]=new int [2]; // Array to store degrees in 0th Index and minutes in 1st Index

private int gboroLong[]={-79,-47};

private int gboroLat[]={36,4};

public static void main(String args[])throws IOException

{

Direction obj=new Direction();

obj.acceptValues();

double rLong,rLat,gLong,gLat,d;

rLong=obj.convertRadians(obj.longitude); // Converting longitude into radians

rLat=obj.convertRadians(obj.latitude);// Converting latitude into radians

gLong=obj.convertRadians(obj.gboroLong);

gLat=obj.convertRadians(obj.gboroLat);

d=Math.atan2(Math.sin(rLong-gLong)*Math.cos(rLat),Math.cos(gLat)*Math.sin(rLat)-Math.sin(gLat)*Math.cos(rLat)*Math.cos(rLong-gLong));

d=d*(180/3.14159);

System.out.println("The direction(in degrees) of the entered location from Greensboro is :"+d);

}

private void acceptValues()throws IOException

{

boolean x;

BufferedReader pm=new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter the degree measure of the longitude");

longitude[0]=Integer.parseInt(pm.readLine());

longitude[0]=longitude[0]%360; // For values greater than 360, converted into a value b/w 0 and 360

do // Loop for checking whether entered value of minutes in valid or not

{

System.out.println("Enter the minutes measure of the longitude");

longitude[1]=Integer.parseInt(pm.readLine());

if (longitude[1]>60 || longitude[1]<-60) // condition for checking validity

{

System.out.println("Entered valus should be between 0 and 60");

x=true;

}

else

x=false;

}while(x);

System.out.println("Enter the degree measure of the latitude");

latitude[0]=Integer.parseInt(pm.readLine());

latitude[0]=latitude[0]%360; // For values greater than 360, converted into a value b/w 0 and 360

do // Loop for checking whether entered value of minutes in valid or not

{

System.out.println("Enter the minutes measure of the latitude");

latitude[1]=Integer.parseInt(pm.readLine());

if (latitude[1]>60 || latitude[1]<-60) // condition for checking validity

{

System.out.println("Entered valus should be between 0 and 60");

x=true;

}

else

x=false;

}while(x);

}

private double convertRadians(int arr[])

{

return (arr[0]+arr[1]/60)*3.14159/180;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote