Consider the plan-landing problem we have discussed in the class where an airpor
ID: 3849966 • Letter: C
Question
Consider the plan-landing problem we have discussed in the class where an airport has one runway and planes request landing. Constraints is that runway request will be granted only if there is a K time gap from either side of the landing request.
For example, suppose K = 3 and a plane request landing time 56. If there are landing requested for 60 and 45 already granted, then the differences from either sides are 60-56 = 4 and 56-45 =11. Satisfies the K=3 constraint. Landing request will be granted. However, if landing times 58 and 45 have already been granted, then 58-56 = 2, which is less than 3. So, landing request will not be granted.
In this problem, you will be implementing several functionalities of this plane landing system using BST (“Landing times BST”). Your plane landing system should first ask for the K value from the user, then implement the following functionalities.
Your landing times BST should store the landing time (use as the key) and the plane flight number in the node.
A) Request landing – input for this functionality is the landing time. You can consider the current time as zero. If the landing time request satisfies the K constraint, grant the landing time and insert the landing time to the landing times BST.
B) Withdraw landing request – A plane can withdraw landing request. This may be due to delay and cancel flight. In this case, remove the landing request from the landing BST.
C) List landing times and the flight number – display the landing times and flights in the
landing times BST.
Write a C or C++ program that Implements above functionality
Explanation / Answer
public class Airplane
{
private String type;
private int status;
public Airplane(int state,String typ)
{
type=typ;
status=state;
}
public void landing(Airplane newValue)
{
if((newValue.status==0)||(newValue.status==1))
{
if(newValue.status==1)
{
newValue.status=0;
}else
{
System.out.println("The "+newValue.type+" has already landed");
}
}else { System.out.println("The airplane status should be '0' for landing or '1' for takeoff , Thanks");}
}
public void takeoff(Airplane newValue)
{
if((newValue.status==0)||(newValue.status==1))
{
if(newValue.status==0)
{
newValue.status=1;
}else
{
System.out.println("The "+newValue.type+" has already takeoff");
}
}else { System.out.println("The airplane status should be '0' for landing or '1' for takeoff , Thanks");}
}
public static void statusCheck(Airplane newValue)
{
switch(newValue.status)
{
case 0:
System.out.println(" Airplane status: The Airplane("+newValue.type+") landed.");
break;
case 1:
System.out.println(" Airplane status: The Airplane ("+newValue.type+")takeoff.");
break;
default:
System.out.println(" The Airplane ("+newValue.type+")status incourrect.");
}
}
public static void main(String[] args)
{
int aps1=1;
String apt1= new String("helicopter");
int aps2=1;
String apt2= new String("AirBus A80");
Airplane myAirP= new Airplane(aps1,apt1);
Airplane uAirP= new Airplane(aps2,apt2);
myAirP.landing(myAirP);
statusCheck(myAirP);
uAirP.takeoff(uAirP);
statusCheck(uAirP);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.