The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
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?
=========================================================
//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 only = c Unknown = u" + "n");
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" + "n");
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: " + "n");
System.out.printf("Enter new Status: " + "n");
System.out.printf("Enter new Runway: " + "n");
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" + "n");
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("nAll 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 + "n" + "Speed: " + speed + "n"
+ "Altitude: " + altitude + "n" + "Type: " + type + "n" + "Status: " + status + "n" + "Runway: " + runway + "n";
}
}
-------------------------------------------------------------------------------
//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);
}
}