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

Implement a java program to simulate an air traffic control using a linked list

ID: 3754953 • Letter: I

Question

Implement a java program to simulate an air traffic control using a linked list (only insertions). This air traffic control must control all flights (takeoffs and landings) on a specific airway.

Takeoff: Insert a new node (flight)

Landing: Remove the specific node (next class exercise).

*note: An airway or air route is a defined corridor that connects one specified location to another at a specified altitude, along which an aircraft that meets the requirements of the airway may be flown. (source: wikipedia)

The program should ask for the following information:

- Flight number (e.g. NAX7091)

- Origin (e.g. Austin, Texas)

- Destination (e.g. Los Angeles, California)

- Airline name (e.g. American Airlines)

- Departure (e.g. Mon 02:00PM)

- Arrival (e.g. Mon 05:00PM)

You need to modify the Aircraft.java file to include the variables. Remember that the Aircraft class must have a next variable.

Using a for loop, insert at least 5 flights.

Implement the printAirTraffic method to print the airway traffic (linked list).

GIVEN:

Aircraft.java

class Aircraft{
String flightNumber;
Aircraft next;
}

Main.Java

class Main{
  
public static void main (String[] arg){   
Aircraft airway = null; //This is the head (the airway)
airway = new Aircraft(); // Creates an empty airway
  
Aircraft flight = airway;

//your code goes here

printAirTraffic(airway);
}
  
public static void printAirTraffic(Aircraft airway){
//Implement this method
}
}

Explanation / Answer

Aircraft.java

class Aircraft {

String flightNumber;

String origin;

String destination;

String airlineName;

String departure;

String arrival;

Aircraft next;

public Aircraft() {

}

public Aircraft(String flightNumber, String origin, String destination, String airlineName, String departure,

String arrival) {

this.flightNumber = flightNumber;

this.origin = origin;

this.destination = destination;

this.airlineName = airlineName;

this.departure = departure;

this.arrival = arrival;

this.next = null;

}

@Override

public String toString() {

return "Aircraft [flightNumber=" + flightNumber + ", origin=" + origin + ", destination=" + destination

+ ", airlineName=" + airlineName + ", departure=" + departure + ", arrival=" + arrival + "]";

}

public String getFlightNumber() {

return flightNumber;

}

public void setFlightNumber(String flightNumber) {

this.flightNumber = flightNumber;

}

public String getOrigin() {

return origin;

}

public void setOrigin(String origin) {

this.origin = origin;

}

public String getDestination() {

return destination;

}

public void setDestination(String destination) {

this.destination = destination;

}

public String getAirlineName() {

return airlineName;

}

public void setAirlineName(String airlineName) {

this.airlineName = airlineName;

}

public String getDeparture() {

return departure;

}

public void setDeparture(String departure) {

this.departure = departure;

}

public String getArrival() {

return arrival;

}

public void setArrival(String arrival) {

this.arrival = arrival;

}

public Aircraft getNext() {

return next;

}

public void setNext(Aircraft next) {

this.next = next;

}

}

Main.java

import java.util.Scanner;

class Main {

public static Aircraft getAirCraftFromUser(Scanner sc) {

Aircraft aircraft = new Aircraft();

System.out.print("Enter flight number: ");

aircraft.setFlightNumber(sc.nextLine());

System.out.print("Enter origin: ");

aircraft.setOrigin(sc.nextLine());

System.out.print("Enter destination: ");

aircraft.setDestination(sc.nextLine());

System.out.print("Enter airline name: ");

aircraft.setAirlineName(sc.nextLine());

System.out.print("Enter departure: ");

aircraft.setDeparture(sc.nextLine());

System.out.print("Enter arrival: ");

aircraft.setArrival(sc.nextLine());

return aircraft;

}

public static void main(String[] arg) {

Aircraft airway = null; // This is the head (the airway)

airway = new Aircraft(); // Creates an empty airway

Aircraft flight = airway;

Scanner sc = new Scanner(System.in);

for(int i = 1; i <= 5; i++) { // take input from user

flight.setNext(getAirCraftFromUser(sc));

flight = flight.getNext();

}

sc.close();

printAirTraffic(airway);

}

public static void printAirTraffic(Aircraft airway) { // to print all the values

for(airway=airway.getNext();airway != null;){

System.out.println(airway);

airway = airway.getNext();

}

}

}

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