In this assignment, you will be simulating an Air Traffic Control tower. This program uses data of the Airplane class type. This is a custom class that you will use for this activity. Each Airplane object represents an actual airplane that is detected by the tower at a particular instance in time. The Airplane object has a number of fields: a horizontal distance in miles from the tower (as a positive decimal number), a bearing (compass direction) from the tower (as an integer from 0 to 360), a positive altitude (height) in feet (as a positive integer) and a call-sign which consists of letters, numbers, and symbols. The Airplane class has the following constructors and methods: Constructors Airplane() - Creates an Airplane with call sign “AAA01” located on the landing strip: 1 mile due north (0°) of the tower at an altitude of 0 feet. Airplane(String cs, double dist, int dir, int alt) - Creates an Airplane with call-sign cs dist miles from the tower on a bearing of dir degrees, at an altitude of alt feet. Notes: alt and dist will always be read as absolute values (non-negative). If dir is not between 0 and 360, the bearing will be set to dir % 360. Methods move(double dist, int dir) - Void method. Changes the Airplane position by dist miles on a heading of dir degrees. gainAlt() - Void method. Increases the altitude of the Airplane by 1000 feet. loseAlt() - Void method. Decreases the altitude of the Airplane by 1000 feet, or to 0 if altitude is less than 1000 feet. getAlt() - Returns an int representing the altitude of the Airplane. toString() - Returns a String representation of the Airplane including all fields. For example: AAL123 - 110.5 miles away at bearing 059°, altitude 4500 feet distTo(Airplane other) - Returns a double representing the distance in miles between this Airplane and the Airplane other You will first write code to create a plane, "Airplane 1", with the default callsign of AAA01, starting in the default position of 1 mile due north (0°) of the tower at an altitude of 0 feet. Your program will then create a second plane, “Airplane 2”, with the callsign of AAA02, starting at a position of 15.8 miles with a bearing of 128° at an altitude of 30,000 feet. Next, your program should ask the user to input the details of a third airplane, "Airplane 3", detected by the tower. This will consist of the call-sign, distance, direction and altitude. Once these inputs have been entered, your program should convert the callsign to use uppercase letters, then create Airplane 3 using these details. Now, your program should make the following changes to the positions of the airplanes: Move Airplane 1 a distance that is equal to the initial distance between Airplane 2 and Airplane 3 on a heading of 65°. In other words, if the distance between Airplane 2 and Airplane 3 is 4.6 miles, then we should move Airplane 4.6 miles on a heading of 65°. Move Airplane 2 a distance of 8.0 miles on a heading of 135°. Move Airplane 3 a distance of 5.0 miles on a heading 55°. Increase the altitude of Airplane 1 by 3,000 feet. Decrease the altitude of Airplane 2 by 2,000 feet. Decrease the altitude of Airplane 3 by 4,000 feet. After this, your program should print the details of the planes with their new positions, the new distances between each of the airplanes, and the new differences in height between each of the airplanes. You should carefully follow the format shown below in the sample runs when you create your program: make sure your program produces the exact same output when you input the sample data into it. Milestones Milestone 1: Write a constructor call to create the first default plane. Write a constructor call to create a second plane with the non-default values. Then write code to get inputs of the correct type for each field for the third plane. Convert the callsign to uppercase and use this data to create Airplane 3. Milestone 2: Write code that prints the relevant details for all three airplanes. Calculates the distance between each of the airplanes and the (positive) difference in altitude between each of the airplanes, then prints these values. Milestone 3: Write code that moves the planes as desired (the first airplane up 3000 feet, the second down 2000 feet, and the third down 4,000 feet, then move the first airplane by the initial distance between the second and third on a heading of 65°, the second 8.0 miles on a heading of 135°, and the third 5.0 miles on a heading of 55°). Repeat the code from milestone 2 to print the new positions. Sample Runs Sample Run 1 Enter the details of the third airplane (call-sign, distance, bearing and altitude): UaL256 12.8 200 22000 Initial Positions: "Airplane 1": AAA01 - 1.0 miles away at bearing 000°, altitude 0 feet "Airplane 2": AAA02 - 15.8 miles away at bearing 128°, altitude 30000 feet "Airplane 3": UAL256 - 12.8 miles away at bearing 200°, altitude 22000 feet Initial Distances: The distance between Airplane 1 and Airplane 2 is 16.43 miles. The distance between Airplane 1 and Airplane 3 is 13.74 miles. The distance between Airplane 2 and Airplane 3 is 16.98 miles. Initial Height Differences: The difference in height between Airplane 1 and Airplane 2 is 30000 feet. The difference in height between Airplane 1 and Airplane 3 is 22000 feet. The difference in height between Airplane 2 and Airplane 3 is 8000 feet. New Positions: "Airplane 1": AAA01 - 17.43 miles away at bearing 062°, altitude 3000 feet "Airplane 2": AAA02 - 23.76 miles away at bearing 130°, altitude 28000 feet "Airplane 3": UAL256 - 9.16 miles away at bearing 182°, altitude 18000 feet New Distances: The distance between Airplane 1 and Airplane 2 is 23.62 miles. The distance between Airplane 1 and Airplane 3 is 23.4 miles. The distance between Airplane 2 and Airplane 3 is 19.5 miles. New Height Differences: The difference in height between Airplane 1 and Airplane 2 is 25000 feet. The difference in height between Airplane 1 and Airplane 3 is 15000 feet. The difference in height between Airplane 2 and Airplane 3 is 10000 feet. Sample Run 2 Enter the details of the third airplane (call-sign, distance, bearing and altitude): aca549 25.3 305 1000 Initial Positions: "Airplane 1": AAA01 - 1.0 miles away at bearing 000°, altitude 0 feet "Airplane 2": AAA02 - 15.8 miles away at bearing 128°, altitude 30000 feet "Airplane 3": ACA549 - 25.3 miles away at bearing 305°, altitude 1000 feet Initial Distances: The distance between Airplane 1 and Airplane 2 is 16.43 miles. The distance between Airplane 1 and Airplane 3 is 24.74 miles. The distance between Airplane 2 and Airplane 3 is 41.09 miles. Initial Height Differences: The difference in height between Airplane 1 and Airplane 2 is 30000 feet. The difference in height between Airplane 1 and Airplane 3 is 1000 feet. The difference in height between Airplane 2 and Airplane 3 is 29000 feet. New Positions: "Airplane 1": AAA01 - 41.52 miles away at bearing 064°, altitude 3000 feet "Airplane 2": AAA02 - 23.76 miles away at bearing 130°, altitude 28000 feet "Airplane 3": ACA549 - 24.05 miles away at bearing 316°, altitude 0 feet New Distances: The distance between Airplane 1 and Airplane 2 is 38.55 miles. The distance between Airplane 1 and Airplane 3 is 54.04 miles. The distance between Airplane 2 and Airplane 3 is 47.75 miles. New Height Differences: The difference in height between Airplane 1 and Airplane 2 is 25000 feet. The difference in height between Airplane 1 and Airplane 3 is 3000 feet. The difference in height between Airplane 2 and Airplane 3 is 28000 feet.

in java

1 answer

To implement the Air Traffic Control tower simulation, we first need to create the Airplane Java class based on the specifications you provided. Then, we will create a main class to handle the creation of airplane objects, user input, moving the airplanes, and printing the required details.

Here is a possible implementation in Java:

import java.util.Scanner;

class Airplane {
    private String callSign;
    private double distance; // in miles
    private int bearing;     // bearing direction
    private int altitude;    // in feet

    // Default constructor
    public Airplane() {
        this.callSign = "AAA01";
        this.distance = 1.0; // 1 mile away
        this.bearing = 0;    // 0° (North)
        this.altitude = 0;   // 0 feet
    }

    // Parameterized constructor
    public Airplane(String cs, double dist, int dir, int alt) {
        this.callSign = cs.toUpperCase(); // Uppercase call sign
        this.distance = dist;
        this.bearing = (dir < 0 || dir >= 360) ? (dir % 360 + 360) % 360 : dir; // Normalize bearing
        this.altitude = alt; // No need for checks as per the problem statement
    }

    // Move the airplane
    public void move(double dist, int dir) {
        this.distance += dist;
        this.bearing = (dir < 0 || dir >= 360) ? (dir % 360 + 360) % 360 : dir; // Ensure bearing is valid
    }

    // Increase altitude
    public void gainAlt() {
        this.altitude += 1000;
    }

    // Decrease altitude
    public void loseAlt() {
        this.altitude = Math.max(0, this.altitude - 1000);
    }

    // Get altitude
    public int getAlt() {
        return this.altitude;
    }

    // String representation
    @Override
    public String toString() {
        return this.callSign + " - " + this.distance + " miles away at bearing " + String.format("%03d", this.bearing) + "°, altitude " + this.altitude + " feet";
    }

    // Calculate distance to another airplane
    public double distTo(Airplane other) {
        // This formula uses the law of cosines for calculating distances
        double lat1 = Math.toRadians(this.bearing);
        double lat2 = Math.toRadians(other.bearing);
        
        return Math.sqrt(Math.pow(this.distance * Math.cos(lat1), 2) + Math.pow(other.distance * Math.cos(lat2), 2)
                - 2 * (this.distance * Math.cos(lat1)) * (other.distance * Math.cos(lat2)) * Math.cos(Math.toRadians(this.bearing - other.bearing)));
    }
}

public class AirTrafficControl {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        // Create the first and second airplanes
        Airplane airplane1 = new Airplane();
        Airplane airplane2 = new Airplane("AAA02", 15.8, 128, 30000);
        
        // User input for the third airplane
        System.out.println("Enter the details of the third airplane (call-sign, distance, bearing and altitude):");
        String callSign = scanner.next();
        double distance3 = scanner.nextDouble();
        int bearing3 = scanner.nextInt();
        int altitude3 = scanner.nextInt();
        Airplane airplane3 = new Airplane(callSign, distance3, bearing3, altitude3);
        
        // Initial positions
        System.out.println("Initial Positions:");
        System.out.printf("\"Airplane 1\": %s%n", airplane1);
        System.out.printf("\"Airplane 2\": %s%n", airplane2);
        System.out.printf("\"Airplane 3\": %s%n", airplane3);
        
        // Initial distances
        double dist12 = airplane1.distTo(airplane2);
        double dist13 = airplane1.distTo(airplane3);
        double dist23 = airplane2.distTo(airplane3);
        System.out.println("Initial Distances:");
        System.out.printf("The distance between Airplane 1 and Airplane 2 is %.2f miles.%n", dist12);
        System.out.printf("The distance between Airplane 1 and Airplane 3 is %.2f miles.%n", dist13);
        System.out.printf("The distance between Airplane 2 and Airplane 3 is %.2f miles.%n", dist23);
        
        // Initial height differences
        int altDiff1And2 = Math.abs(airplane1.getAlt() - airplane2.getAlt());
        int altDiff1And3 = Math.abs(airplane1.getAlt() - airplane3.getAlt());
        int altDiff2And3 = Math.abs(airplane2.getAlt() - airplane3.getAlt());
        System.out.println("Initial Height Differences:");
        System.out.printf("The difference in height between Airplane 1 and Airplane 2 is %d feet.%n", altDiff1And2);
        System.out.printf("The difference in height between Airplane 1 and Airplane 3 is %d feet.%n", altDiff1And3);
        System.out.printf("The difference in height between Airplane 2 and Airplane 3 is %d feet.%n", altDiff2And3);
        
        // Move airplanes as per instructions
        airplane1.move(dist23, 65); // Move Airplane 1 to 65°
        airplane2.move(8.0, 135);    // Move Airplane 2 to 135°
        airplane3.move(5.0, 55);      // Move Airplane 3 to 55°
        airplane1.gainAlt();          // Increase altitude of Airplane 1 by 3000 feet
        airplane2.loseAlt();          // Decrease altitude of Airplane 2 by 2000 feet
        airplane3.loseAlt();          // Decrease altitude of Airplane 3 by 4000 feet
        
        // New positions
        System.out.println("New Positions:");
        System.out.printf("\"Airplane 1\": %s%n", airplane1);
        System.out.printf("\"Airplane 2\": %s%n", airplane2);
        System.out.printf("\"Airplane 3\": %s%n", airplane3);
        
        // New distances
        dist12 = airplane1.distTo(airplane2);
        dist13 = airplane1.distTo(airplane3);
        dist23 = airplane2.distTo(airplane3);
        System.out.println("New Distances:");
        System.out.printf("The distance between Airplane 1 and Airplane 2 is %.2f miles.%n", dist12);
        System.out.printf("The distance between Airplane 1 and Airplane 3 is %.2f miles.%n", dist13);
        System.out.printf("The distance between Airplane 2 and Airplane 3 is %.2f miles.%n", dist23);
        
        // New height differences
        altDiff1And2 = Math.abs(airplane1.getAlt() - airplane2.getAlt());
        altDiff1And3 = Math.abs(airplane1.getAlt() - airplane3.getAlt());
        altDiff2And3 = Math.abs(airplane2.getAlt() - airplane3.getAlt());
        System.out.println("New Height Differences:");
        System.out.printf("The difference in height between Airplane 1 and Airplane 2 is %d feet.%n", altDiff1And2);
        System.out.printf("The difference in height between Airplane 1 and Airplane 3 is %d feet.%n", altDiff1And3);
        System.out.printf("The difference in height between Airplane 2 and Airplane 3 is %d feet.%n", altDiff2And3);
        
        // Close the scanner
        scanner.close();
    }
}

Explanation:

  1. Class Structure: The Airplane class encapsulates the relevant properties and behaviors of an airplane. It has constructors for default and parameterized initialization, methods to move the airplane and adjust its altitude, a method to calculate distance to another airplane, and a method for a textual representation.

  2. User Input: The AirTrafficControl class gets user input for the third airplane's properties.

  3. Distance Calculation: A simple method calculates the distance between airplanes based on their distances and bearings.

  4. Altitude Management: The program allows for increasing and decreasing the altitude with the specified constraints.

  5. Output: All relevant information is printed to the console in the specified format.

Important Note:

The distance calculation used in this sample code is simplistic and assumes flat Earth-like geometry for demonstration purposes. In a real-world application, more complex formulas involving trigonometry might be needed to accurately calculate distances between points based on geographical coordinates. This is a basic demonstration. Adjust the distance calculation as needed to reflect the actual aeronautical computations.

Make sure to run the program with various inputs to test its functionality!

Similar Questions
    1. answers icon 1 answer
  1. An air traffic controller is in a control tower 92 m above the ground. Heestimates his angle of elevation to a passing airplane
    1. answers icon 1 answer
  2. write in java programObjective: develop a program to simulate the control of traffic lights at an intersection using static
    1. answers icon 1 answer
    1. answers icon 3 answers
more similar questions