Question: How can I write these two methods in java? please help 1. Write a method with this signature: public List getAirportsWithin(String code, double withinDist) which

How can I write these two methods in java? please help

1.

  1. Write a method with this signature:

public List getAirportsWithin(String code, double withinDist) which returns a list of Airports which are within withinDist of the Airport with code.

2.

  1. Write a method with this signature:

public List getAirportsWithin(String code1, String code2, double withinDist)

Returns a list of Airports which are within withinDist of both the Airports that correspond to code1 and code2. For example, find all airports that are within 100 miles of both the Valdosta and Moody airports.

Hints:

  1. Call the overloaded getAirportsWithin(String code, double withinDist) twice, once with each code and the distance. This will yield two lists. Then, put them together for the answer.
  2. Using, airportsMedium.txt, this is a reasonable test: getAirportsWithin("ANB", "VLD", 150) which returns 3 cities--------------------------------------

public class Airport { private String code; private String city; private String state; private double latitude; private double longtitude; public Airport(String code, double latitude, double longtitude, String city, String state ) { this.code=code; this.latitude=latitude; this.longtitude=longtitude; this.city=city; this.state=state;

} protected Airport (String code) { this.code=code; } public String getCode() { return code; } public double getLatitude() { return latitude; } public double getLongtitude() { return longtitude; } public String getCity() { return city; } public String getState() { return state; }

----------------------------------------------------

public class DistanceCalculator {

private final static double conversionRateDR = 0.017453; private final static double conversionRateKM = 0.621371; private final static double radiusEarth = 6371.01;

/** * Returns the distance between two pairs of latitude & longitude * @param lat1 * @param long1 * @param lat2 * @param long2 * @return */ public static double getDistance(double lat1, double long1, double lat2, double long2){

double lat1R, long1R, lat2R, long2R;

lat1R = convertToRadians(lat1); lat2R = convertToRadians(lat2);

long1R = convertToRadians(long1); long2R = convertToRadians(long2);

double distance = Math.acos(Math.sin(lat1R) * Math.sin(lat2R) + Math.cos(lat1R) * Math.cos(lat2R) * Math.cos(long2R - long1R)) * radiusEarth; return convertToMiles(distance); } private static double convertToMiles(double distance){ return distance * conversionRateKM; }

private static double convertToRadians(double degree){ return degree * conversionRateDR; } }

ANB 33.58 85.85 Anniston AL AUO 32.67 85.44 Auburn AL BHM 33.57 86.75 Birmingham AL CKL 32.9 87.25 Centreville AL DHN 31.32 85.45 Dothan AL OZR 31.28 85.72 FortRucker AL GAD 33.97 86.09 Gadsden AL HSV 34.65 86.77 Huntsville AL MXF 32.38 86.37 MaxwellAFB AL MOB 30.68 88.25 Mobile AL BFM 30.63 88.07 MobileAeros AL MGM 32.3 86.4 Montgomery AL MSL 34.75 87.62 MuscleShoal AL SEM 32.34 86.99 Selma AL TOI 31.87 86.02 Troy AL TCL 33.23 87.62 Tuscaloosa AL AQQ 29.73 85.03 Apalachicola FL 90J 29.12 81.57 AstorNAS FL AGR 28.08 81.55 AvonParkG FL XMR 28.47 80.55 CapeCanaveral FL NZC 30.22 81.88 Cecil FL CEW 30.78 86.52 Crestview FL CTY 29.62 83.1 CrossCity FL DAB 29.18 81.05 DaytonaBeach FL EGI 30.65 86.52 DukeFld FL VPS 30.48 86.53 EglinAFB FL X91 27.6 82.77 EgmontKey FL FXE 26.13 80.13 FortLauderd FL FMY 26.58 81.87 FortMyers FL FLL 26.07 80.15 FtLauderdale FL RSW 26.65 81.87 FtMyers FL GNV 29.68 82.27 Gainesville FL HST 25.48 80.38 Homestead FL HRT 30.43 86.68 HurlburtFld FL CRG 30.33 81.52 Jacksonville FL JAX 30.5 81.7 Jacksonville FL NIP 30.23 81.68 Jacksonville FL EYW 24.55 81.75 KeyWest FL NQX 24.57 81.68 KeyWestNAS FL LAL 28.03 81.95 Lakeland FL MCF 27.85 82.52 MacdillAFB FL MAI 30.84 85.18 Marianna FL NRB 30.4 81.42 MayportNAS FL MLB 28.1 80.63 Melbourne FL MIA 25.82 80.28 MiamiIntl FL OPF 25.92 80.28 Miami/Opa FL TMB 25.65 80.43 Miami/Tamiami FL APF 26.13 81.8 Naples FL X68 28.62 80.68 NasaShuttle FL MCO 28.43 81.32 Orlando FL ORL 28.55 81.33 Orlando FL PFN 30.2 85.68 PanamaCity FL COF 28.23 80.6 PatrickAFB FL NPA 30.35 87.32 Pensacola FL PNS 30.47 87.2 Pensacola FL TBW 27.97 82.6 Ruskin FL PIE 27.92 82.68 SaintPeters FL SFB 28.78 81.25 Sanford FL SRQ 27.4 82.55 Sarasota FL TLH 30.38 84.37 Tallahassee FL TPA 27.97 82.53 TampaIntl FL TIX 28.52 80.8 Titusville FL PAM 30.07 85.58 TyndallAFB FL VRB 27.65 80.42 VeroBeach FL PBI 26.68 80.12 WPalmBeach FL NSE 30.72 87.02 WhitingFld FL ABY 31.53 84.18 Albany GA AMG 31.53 82.52 Alma GA AHN 33.95 83.32 Athens GA ATL 33.65 84.42 Atlanta GA ATL 33.65 84.42 Atlanta GA PDK 33.88 84.3 Atlanta/Dklb GA FTY 33.78 84.52 Atlanta/Fltn GA AGS 33.37 81.97 Augusta/Bush GA SSI 31.15 81.38 Brunswick GA CSG 32.52 84.93 Columbus GA MGE 33.92 84.52 DobbinsAFB GA MGF 34.53 84.87 DobbinsAFB GA LSF 32.33 85 FortBenning GA LHW 31.88 81.57 FtStewart GA SVN 32.02 81.15 HunterAaf GA LGC 33.01 85.07 LaGrange GA MCN 32.7 83.65 Macon/Lewis GA VAD 30.97 83.2 MoodyAFB GA WRB 32.63 83.6 RobinsAFB GA RMG 34.35 85.17 Rome/Russell GA SAV 32.13 81.2 SavannahMun GA VLD 30.78 83.28 Valdosta GA AYS 31.25 82.4 Waycross GA

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!