To represent the details of airplanes and their relationships in Java, we can create a simple program that defines an Airplane
class. This class will store information such as the call sign, distance, bearing, and altitude. Additionally, we can calculate distances and height differences based on the information provided.
Here's a basic implementation to model the airplanes based on the details you've provided:
class Airplane {
String callSign;
double distance; // in miles
double bearing; // in degrees
int altitude; // in feet
public Airplane(String callSign, double distance, double bearing, int altitude) {
this.callSign = callSign;
this.distance = distance;
this.bearing = bearing;
this.altitude = altitude;
}
@Override
public String toString() {
return "Airplane{" +
"callSign='" + callSign + '\'' +
", distance=" + distance +
", bearing=" + bearing +
", altitude=" + altitude +
'}';
}
}
public class AirplaneSystem {
public static void main(String[] args) {
// Initial Positions
Airplane airplane1 = new Airplane("AAA01", 1.0, 0, 0);
Airplane airplane2 = new Airplane("AAA02", 15.8, 128, 30000);
Airplane airplane3 = new Airplane("UAL256", 12.8, 200, 22000);
// New Positions
airplane1 = new Airplane("AAA01", 17.43, 62, 3000);
airplane2 = new Airplane("AAA02", 23.76, 130, 28000);
airplane3 = new Airplane("UAL256", 9.16, 182, 18000);
// Displaying the new positions of airplanes
System.out.println("New Positions:");
System.out.println(airplane1);
System.out.println(airplane2);
System.out.println(airplane3);
// Example calculations based on the new positions
calculateDistances(airplane1, airplane2, airplane3);
calculateHeightDifferences(airplane1, airplane2, airplane3);
}
static void calculateDistances(Airplane a1, Airplane a2, Airplane a3) {
double distance12 = calculateDistance(a1.distance, a2.distance);
double distance13 = calculateDistance(a1.distance, a3.distance);
double distance23 = calculateDistance(a2.distance, a3.distance);
System.out.println("New Distances:");
System.out.printf("Distance between Airplane 1 and 2: %.2f miles%n", distance12);
System.out.printf("Distance between Airplane 1 and 3: %.2f miles%n", distance13);
System.out.printf("Distance between Airplane 2 and 3: %.2f miles%n", distance23);
}
static double calculateDistance(double distance1, double distance2) {
// Assuming in a real scenario you would calculate based on bearing,
// but for this example, let's just return the absolute difference for simplicity.
return Math.abs(distance1 - distance2); // Placeholder for actual distance calculation logic
}
static void calculateHeightDifferences(Airplane a1, Airplane a2, Airplane a3) {
int heightDifference12 = Math.abs(a1.altitude - a2.altitude);
int heightDifference13 = Math.abs(a1.altitude - a3.altitude);
int heightDifference23 = Math.abs(a2.altitude - a3.altitude);
System.out.println("New Height Differences:");
System.out.printf("Height difference between Airplane 1 and 2: %d feet%n", heightDifference12);
System.out.printf("Height difference between Airplane 1 and 3: %d feet%n", heightDifference13);
System.out.printf("Height difference between Airplane 2 and 3: %d feet%n", heightDifference23);
}
}
Explanation:
- Airplane Class: Defines the properties of an airplane (call sign, distance, bearing, altitude).
- AirplaneSystem Class: Contains the
main
method where we create instances of three airplanes with the new positions and print their details. - Distance and Height Difference Calculations: Placeholder methods are provided to calculate distances based on a simple difference logic, and height differences based on the altitude of the airplanes.
This is a basic structure, and you can expand on the distance calculation logic using geographic mathematics if you'd like to be more precise based on the bearings and distances.