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

Java Lab Assignment Create a class called Airport with the following fields: Ide

ID: 3688127 • Letter: J

Question

Java Lab Assignment

Create a class called Airport with the following fields: Identifier. Coordinates which consist of Latitude and Longitude. Latitude is positive to indicate is North of the Equator and negative when it's located in the southern hemisphere. Longitude is negative to indicate is West and positive to indicate it's East of the Greenwich median. A magnetic variation which also is indicated negative for West and positive for East. It is OK to have no magnetic variation. Elevation above sea level in feet.

Add a static method that accepts four doubles which are two set off coordinates (double lat1, double long1, double lat2, double long2) and returns the distance in nautical miles using the formula According to http://en.wikipedia.org/wiki/Great-circle_distance, the great circle distance based on two coordinates in nautical miles is given by: d = r * where r is the radius of the earth and = acos(sin(1) * sin(2) + cos(1)*cos(2) * cos) The radius of the earth is a constant and its value in radians is r = 10800 / PI Given 2 coordinates (Lat1, Long1, Lat2, and Long2) the formula can be re-written as: = acos(sin(Lat1) * sin(Lat2) + cos(Lat1) * cos(Lat2) * cos(Long1 – Long2)) Because the coordinates on earth are given in degrees, you need to convert the degrees into radians by multiplying the degrees * PI / 180. For example San Diego airport has the values ID: SAN, Lat: 32.7335556, Long: -117.1896667, Var: 14, Elev: 16.8' (http://www.airnav.com/airport/SAN) The class should have an accessor and mutator methods for each field.

Explanation / Answer

import java.util.*;
import java.lang.*;
import java.io.*;

class AeroDistance
{
   public static void main (String[] args) throws java.lang.Exception
   {
       System.out.println(distance(32.9697, -96.80322, 29.46786, -98.53506, "M") + " Miles ");
       System.out.println(distance(32.9697, -96.80322, 29.46786, -98.53506, "K") + " Kilometers ");
       System.out.println(distance(32.9697, -96.80322, 29.46786, -98.53506, "N") + " Nautical Miles ");
   }

   private static double distance(double lat1, double lon1, double lat2, double lon2, String unit) {
       double theta = lon1 - lon2;
       double dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2)) + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.cos(deg2rad(theta));
       dist = Math.acos(dist);
       dist = rad2deg(dist);
       dist = dist * 60 * 1.1515;
       if (unit == "K") {
           dist = dist * 1.609344;
       } else if (unit == "N") {
           dist = dist * 0.8684;
       }

       return (dist);
   }
  
   private static double deg2rad(double deg) {
       return (deg * Math.PI / 180.0);
   }

   private static double rad2deg(double rad) {
       return (rad * 180 / Math.PI);
   }
}

output:

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