} //end /** * This method will return all of the flight * details including the airline, flight number, * and distance between two city objects. * @return -String representing the flight details */ public String printFlightDetails() { var formatter = NumberFormat.getNumberInstance(); StringBuilder sb = new StringBuilder(); sb.Append(airLineName + " " + flightNumber + "\n"); sb.Append(value: OriginCity.getName() + " to " + destinationcity.getName() + "\n"); sb.Append("Distance: " + formatter.format(this.calcDistanceToFly()) + " miles.\n"); return(sb.ToString()); } //end printFlightDetails
/** * Method uses the haversine formulae * to calculate the distance around the * globe from one city to another. * @return - distance in miles */ public double calcDistanceToFly() { double R = 6371000; double lat1 = OriginCity.getLatitude(); double lat2 = destinationcity.getLatitude(); double lon1 = OriginCity.getLongitude(); double lon2 = destinationcity.getLongitude(); double lat1Radians = Math.PI * (lat1); double lat2Radians = Math.PI * (lat2); double lon1Radians = Math.PI * (lon1); double lon2Radians = Math.PI * (lon2); double deltaLat = Math.PI * (lat2 - lat1); double deltaLon = Math.PI * (lon2 - lon1); double a = Math.Pow(Math.Sin(deltaLat / 2), 2) + (Math.Cos(lat1Radians) * Math.Cos(lat2Radians) * Math.Pow(Math.Sin(deltaLon / 2), 2)); double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a)); double distance = R * c; return(distance * 0.000621371); } //end