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

I need a timer to be enabled so if I select \"c\" set the status as \"Cleared fo

ID: 3573921 • Letter: I

Question

I need a timer to be enabled so if I select "c" set the status as "Cleared for Landing" then = 5 seconds timer the automatically changes status = "Descending" then= 5 seconds then automatically changes auto status = "Landing" = 5 seconds then finally automatically changes to status ="Arrived" this ends select System.out.println("Change Flight Status = c");
if you select "ok" from the menu which is "Cleared for Landing" I was trying to use timer.schedule(new MyTimerTask(),5000); and then the status would automatically change from "Cleared for Landing" to "Descending" and 5 seconds after that the flight status would change to "Landing" and last.. 5 seconds the flight status would change to "Arrived". all using automation with something like the timer.schedule(new MyTimerTask(),5000); . can you help set the flight status?

This application is working I just need to land and take off with automation. the Main menu is working. It us my final

===================================
//public void schedule(TimerTask task, long delay,long period)
-
// it will execute timer task after delay of 5 seconds
// timer.schedule(new MyTimerTask(),5000);
//
import java.util.*;

public class ATControl {
private ArrayList aircrafts;
static Scanner in = new Scanner(System.in);

// list of planes
static String[] planeList = { "Wide-body Airliner = w", "Regional Airliner = r", "Private Plane = p", "Military = m", "Cargo only: c", "Unknown = u" };


ATControl()
{
aircrafts = new ArrayList();
}
// add plane and details
public void addToList() {

System.out.printf("Enter flight number: ");
String flight = in.nextLine();

// type of plane
System.out.printf("Wide-body Airliner = w Regional Airliner = r Private Plane = p Military = m Cargo Unknown = u" + " ");
System.out.printf("Enter type of plane, ", "Choose from: " + planeList);
String type = in.nextLine();
try {
if (type.equals("w")) {
System.out.println("Wide-body Airliner");
type = "Wide-body Airliner";
} else if (type.equals("r")) {
System.out.println("Regional Airliner");
type = "Regional Airliner";
} else if (type.equals("p")) {
System.out.println("Private Plane");
type = "Private Plane";
} else if (type.equals("m")) {
System.out.println("Military");
type = "Military";
} else if (type.equals("c")) {
System.out.println("Cargo only");
type = "Cargo only";
} else if (type.equals("u")) {
System.out.println("Unknown");
type = "Unknown";
} else
type = null;
} catch (InputMismatchException i) {
System.out.println("You must enter valid command: " + planeList);
}

// plane speed
System.out.printf("Enter current speed: ");
String speed = in.nextLine();

// add Altitude
System.out.printf("Enter current altitude: ");
String alt = in.nextLine();

// add Status
System.out.printf("Cleared for Departure = c Taking Off = t Flying = f Landing = l Cleard for Landing = ok Descending = d Landing = l Arrived = a" + " ");
System.out.printf("Enter Status of Flight: ");
String status = in.nextLine();
try {
if (status.equals("c")) {
System.out.println("Cleared for Departure");
status = "Cleared for Departure";

} else if(status.equals("t")) {
System.out.println("Taking Off");
status = "Taking Off";

} else if (status.equals("f")) {
System.out.println("Flying");
status = "Flying";

} else if (status.equals("ok")) {
System.out.println("Cleard for Landing");
status = "Cleard for Landing";

} else if (status.equals("d")) {
System.out.println("Descending");
status = "Descending";

} else if(status.equals("l")) {
System.out.println("Landing");
status = "Landing";

} else if (status.equals("a")) {
System.out.println("Arrived");
status = "Arrived";

} else
status = null;
} catch (InputMismatchException i) {
System.out.println("You must enter valid Status: " + planeList);
}

// add Runway
System.out.printf("Enter Runway: ");
String runway = in.nextLine();


// Aircraft
Aircraft aircraft = new Aircraft(flight, speed, alt, type, status, runway);
aircrafts.add(aircraft);

}

// show flight planeList.set(status, 22);

public void showFlight() {
System.out.printf("Enter flight number for details: ");
String flight = in.nextLine();
for (Aircraft aircraft : aircrafts) {
if (aircraft.getNumber().equals(flight)) {
System.out.println(aircraft);
}
}
}
// change flight status & runway
public void changeFlight() {
System.out.printf("Enter flight number to change Status: " + " ");
System.out.printf("Enter new Status: " + " ");
System.out.printf("Enter new Runway: " + " ");
String flight = in.nextLine();
for (Aircraft aircraft : aircrafts) {
if (aircraft.getNumber().equals(flight)) {
System.out.println(aircraft);
if (aircraft.getNumber().equals(flight))


// plane speed
System.out.printf("Enter current speed: ");
String speed = in.nextLine();

// set If condition satisfied aircraft attributes by
// calling function of Aircraft class to set its attributes
aircraft.setSpeed(speed);

// add Altitude
System.out.printf("Enter current altitude: ");
String alt = in.nextLine();

// set If condition satisfied aircraft attributes by
// calling function of Aircraft class to set its attributes
aircraft.setAltitude(alt);

// add Status
System.out.printf("Cleared for Departure = c Taking Off = t Flying = f Landing = l Cleard for Landing = ok Descending = d Landing = l Arrived = a" + " ");
System.out.printf("Enter Status of Flight: ");
String status = in.nextLine();

try {
if (status.equals("c")) {
System.out.println("Cleared for Departure");
status = "Cleared for Departure";

} else if(status.equals("t")) {
System.out.println("Taking Off");
status = "Taking Off";

} else if (status.equals("f")) {
System.out.println("Flying");
status = "Flying";

} else if (status.equals("ok")) {
System.out.println("Cleard for Landing");
status = "Cleard for Landing";

} else if (status.equals("d")) {
System.out.println("Descending");
status = "Descending";

} else if(status.equals("l")) {
System.out.println("Landing");
status = "Landing";

} else if (status.equals("a")) {
System.out.println("Arrived");
status = "Arrived";

} else
status = null;
} catch (InputMismatchException i) {
System.out.println("You must enter valid Status: " + planeList);
}

// set If condition satisfied aircraft attributes by
// calling function of Aircraft class to set its attributes
aircraft.setStatus(status);

// add Runway
System.out.printf("Enter Runway: ");
String runway = in.nextLine();

// set If condition satisfied aircraft attributes by
// calling function of Aircraft class to set its attributes
aircraft.setRunway(runway);
System.out.println(aircraft);
}
}
} //end changeFlight


// display all flights
public void displayAll() {
System.out.printf(" All flights: ");
for (Aircraft aircraft : aircrafts) {
System.out.println(aircraft);
}
}

// remove flight
public void removeFlight() {
System.out.printf("Enter flight number to be removed: ");
String flight = in.nextLine();
int index = 0;
for (Aircraft aircraft : aircrafts) {

if ((aircraft.getNumber()).equals(flight)) {

break;
}
index++;
}
aircrafts.remove(index);

}
}
-------------------------------------------------------------------------
//package airTraffic;

public class Aircraft {
private String number;
private String speed;
private String altitude;
private String type;
private String status;
private String runway;

/***
* Constructor
*
* @param number
* @param speed
* @param altitude
* @param type
* @param status
* @param runway
*/
public Aircraft(String number, String speed, String altitude, String type, String status, String runway) {
this.number = number;
this.speed = speed;
this.altitude = altitude;
this.type = type;
this.status = status;
this.runway = runway;
}

/*
* @return the number
*/
public String getNumber() {
return number;
}

/*
* @param number
* the number to set
*/
public void setNumber(String number) {
this.number = number;
}

/*
* @return the speed
*/
public String getSpeed() {
return speed;
}

/*
* @param speed
* the speed to set
*/
public void setSpeed(String speed) {
this.speed = speed;
}

/**
* @return the altitude
*/
public String getAltitude() {
return altitude;
}

/**
* @param altitude
* the altitude to set
*/
public void setAltitude(String altitude) {
this.altitude = altitude;
}

/**
* @return the type
*/
public String getType() {
return type;
}

/**
* @param type
* the type to set
*/
public void setType(String type) {
this.type = type;
}
/**
* @return the status
*/
public String getStatus() {
return status;
}

/**
* @param status
* the status to set
*/
public void setStatus(String status) {
this.status = status;
}
/**
* @return the runway
*/
public String getRunway() {
return runway;
}

/**
* @param runway
* the runway to set
*/
public void setRunway(String runway) {
this.runway = runway;
}


public String toString() {
return "Flight Number: " + number + " " + "Speed: " + speed + " "
+ "Altitude: " + altitude + " " + "Type: " + type + " " + "Status: " + status + " " + "Runway: " + runway + " ";
}

}
-------------------------------------------------------------------------------
//package airTraffic;

import java.util.InputMismatchException;
import java.util.Scanner;

public class Main {
static Scanner in = new Scanner(System.in);

/***
* Driver
*
* @param args
*/
public static void main(String[] args) {
ATControl atControl =new ATControl();
do {
try {
System.out.println("Jayden International! ");
System.out.println("Please enter command to proceed: ");
System.out.println("Enter new aircraft = e");
System.out.println("Display all aircraft = d");
System.out.println("Show specific flight = s");
System.out.println("Remove specific flight = r");
System.out.println("Change Flight Status = c");
System.out.println("Quit Program = q");
String command = in.nextLine();
if ((command).equals("e")) {
atControl.addToList(); // need to somehow "start" this class
} else if ((command).equals("d")) {
atControl.displayAll();
} else if ((command).equals("s")) {
atControl.showFlight();
} else if ((command).equals("r")) {
atControl.removeFlight();
} else if ((command).equals("c")) {
atControl.changeFlight();
} else if ((command).equals("q")) {
System.out.println("Exiting Prgram");
break;
}else if ((command).equals(null)){

}
}
catch (InputMismatchException exc) {
System.out.println("Wrong entry, please try again:");
}
} while (true);

}

}

Explanation / Answer

PROGRAM CODE:

//Made changes only inthe following class

package sample;

//public void schedule(TimerTask task, long delay,long period)-

// it will execute timer task after delay of 5 seconds

// timer.schedule(new MyTimerTask(),5000);

//

import java.util.*;

public class ATControl {

private ArrayList<Aircraft> aircrafts;

private String stat;

private String flightStatus;

private int stepNum = 0;

static Scanner in = new Scanner(System.in);

// list of planes

static String[] planeList = { "Wide-body Airliner = w", "Regional Airliner = r", "Private Plane = p", "Military = m", "Cargo only: c", "Unknown = u" };

ATControl()

{

aircrafts = new ArrayList<Aircraft>();

}

// add plane and details

public void addToList() {

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

String flight = in.nextLine();

// type of plane

System.out.printf("Wide-body Airliner = w Regional Airliner = r Private Plane = p Military = m Cargo Unknown = u" + " ");

System.out.printf("Enter type of plane, ", "Choose from: " + planeList);

String type = in.nextLine();

try {

if (type.equals("w")) {

System.out.println("Wide-body Airliner");

type = "Wide-body Airliner";

} else if (type.equals("r")) {

System.out.println("Regional Airliner");

type = "Regional Airliner";

} else if (type.equals("p")) {

System.out.println("Private Plane");

type = "Private Plane";

} else if (type.equals("m")) {

System.out.println("Military");

type = "Military";

} else if (type.equals("c")) {

System.out.println("Cargo only");

type = "Cargo only";

} else if (type.equals("u")) {

System.out.println("Unknown");

type = "Unknown";

} else

type = null;

} catch (InputMismatchException i) {

System.out.println("You must enter valid command: " + planeList);

}

// plane speed

System.out.printf("Enter current speed: ");

String speed = in.nextLine();

// add Altitude

System.out.printf("Enter current altitude: ");

String alt = in.nextLine();

// add Status

System.out.printf("Cleared for Departure = c Taking Off = t Flying = f Landing = l Cleard for Landing = ok Descending = d Landing = l Arrived = a" + " ");

System.out.printf("Enter Status of Flight: ");

String status = in.nextLine();

try {

if (status.equals("c")) {

System.out.println("Cleared for Departure");

status = "Cleared for Departure";

} else if(status.equals("t")) {

System.out.println("Taking Off");

status = "Taking Off";

} else if (status.equals("f")) {

System.out.println("Flying");

status = "Flying";

} else if (status.equals("ok")) {

System.out.println("Cleard for Landing");

status = "Cleard for Landing";

} else if (status.equals("d")) {

System.out.println("Descending");

status = "Descending";

} else if(status.equals("l")) {

System.out.println("Landing");

status = "Landing";

} else if (status.equals("a")) {

System.out.println("Arrived");

status = "Arrived";

} else

status = null;

} catch (InputMismatchException i) {

System.out.println("You must enter valid Status: " + planeList);

}

// add Runway

System.out.printf("Enter Runway: ");

String runway = in.nextLine();

// Aircraft

Aircraft aircraft = new Aircraft(flight, speed, alt, type, status, runway);

aircrafts.add(aircraft);

}

// show flight planeList.set(status, 22);

public void showFlight() {

System.out.printf("Enter flight number for details: ");

String flight = in.nextLine();

for (Aircraft aircraft : aircrafts) {

if (aircraft.getNumber().equals(flight)) {

System.out.println(aircraft);

}

}

}

// change flight status & runway

public void changeFlight() {

System.out.printf("Enter flight number to change Status: " + " ");

System.out.printf("Enter new Status: " + " ");

System.out.printf("Enter new Runway: " + " ");

String flight = in.nextLine();

for (Aircraft aircraft : aircrafts) {

if (aircraft.getNumber().equals(flight)) {

System.out.println(aircraft);

if (aircraft.getNumber().equals(flight))

// plane speed

System.out.printf("Enter current speed: ");

String speed = in.nextLine();

// set If condition satisfied aircraft attributes by

// calling function of Aircraft class to set its attributes

aircraft.setSpeed(speed);

// add Altitude

System.out.printf("Enter current altitude: ");

String alt = in.nextLine();

// set If condition satisfied aircraft attributes by

// calling function of Aircraft class to set its attributes

aircraft.setAltitude(alt);

// add Status

//made a function below to automate the status process

System.out.printf("Cleared for Departure = c Taking Off = t Flying = f Landing = l Cleard for Landing = ok Descending = d Landing = l Arrived = a" + " ");

System.out.printf("Enter Status of Flight: ");

String status = in.nextLine();

if (status.equals("c")) {

   System.out.println("Cleared for Departure");

   status = "Cleared for Departure";

   } else if(status.equals("t")) {

   System.out.println("Taking Off");

   status = "Taking Off";

   } else if (status.equals("f")) {

   System.out.println("Flying");

   status = "Flying";

   } else automateStatus(status);

try {

   Thread.sleep(15000);

} catch (InterruptedException e) {

   // TODO Auto-generated catch block

   e.printStackTrace();

}

// set If condition satisfied aircraft attributes by

// calling function of Aircraft class to set its attributes

aircraft.setStatus(flightStatus);

// add Runway

System.out.printf("Enter Runway: ");

String runway = in.nextLine();

// set If condition satisfied aircraft attributes by

// calling function of Aircraft class to set its attributes

aircraft.setRunway(runway);

System.out.println(aircraft);

}

}

} //end changeFlight

public void automateStatus(String status)

{

   stat = status;

   try {

   stat = status;

   Timer timer = new Timer();

   timer.scheduleAtFixedRate(new TimerTask() {

      

       @Override

       public void run() {

           if (stat.equals("ok")) {

               System.out.println("Cleard for Landing");

               flightStatus = "Cleard for Landing";

               stat = "d";

               } else if (stat.equals("d")) {

               System.out.println("Descending");

               flightStatus = "Descending";

               stat = "l";

               } else if(stat.equals("l")) {

               System.out.println("Landing");

               flightStatus = "Landing";

               stat = "a";

               } else if (stat.equals("a")) {

               System.out.println("Arrived");

               flightStatus = "Arrived";

               this.cancel();

               timer.cancel();

               } else

                   flightStatus = null;

       }

   }, 0, 5000);

  

  

   } catch (InputMismatchException i) {

   System.out.println("You must enter valid Status: " + planeList);

   }

  

}

// display all flights

public void displayAll() {

System.out.printf(" All flights: ");

for (Aircraft aircraft : aircrafts) {

System.out.println(aircraft);

}

}

// remove flight

public void removeFlight() {

System.out.printf("Enter flight number to be removed: ");

String flight = in.nextLine();

int index = 0;

for (Aircraft aircraft : aircrafts) {

if ((aircraft.getNumber()).equals(flight)) {

break;

}

index++;

}

aircrafts.remove(index);

}

}

OUTPUT:

Jayden International!

Please enter command to proceed:

Enter new aircraft = e

Display all aircraft = d

Show specific flight = s

Remove specific flight = r

Change Flight Status = c

Quit Program = q

e

Enter flight number: 123

Wide-body Airliner = w Regional Airliner = r Private Plane = p Military = m Cargo Unknown = u

Enter type of plane, w

Wide-body Airliner

Enter current speed: 12000

Enter current altitude: 2000

Cleared for Departure = c Taking Off = t Flying = f Landing = l Cleard for Landing = ok Descending = d Landing = l Arrived = a

Enter Status of Flight: l

Landing

Enter Runway: run1

Jayden International!

Please enter command to proceed:

Enter new aircraft = e

Display all aircraft = d

Show specific flight = s

Remove specific flight = r

Change Flight Status = c

Quit Program = q

c

Enter flight number to change Status:

Enter new Status:

Enter new Runway:

123

Flight Number: 123

Speed: 12000

Altitude: 2000

Type: Wide-body Airliner

Status: Landing

Runway: run1

Enter current speed: 3000

Enter current altitude: 3000

Cleared for Departure = c Taking Off = t Flying = f Landing = l Cleard for Landing = ok Descending = d Landing = l Arrived = a

Enter Status of Flight: ok

Cleard for Landing

Descending

Landing

Arrived

Enter Runway: run1

Flight Number: 123

Speed: 3000

Altitude: 3000

Type: Wide-body Airliner

Status: Arrived

Runway: run1

Jayden International!

Please enter command to proceed:

Enter new aircraft = e

Display all aircraft = d

Show specific flight = s

Remove specific flight = r

Change Flight Status = c

Quit Program = q

q

Exiting Prgram

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