give me a code pls
package com.codegym.task.task16.task1615;
/*
Airport
*/
public class Solution {
public static volatile Runway RUNWAY = new Runway(); // 1 runway
public static void main(String[] args) throws InterruptedException {
Plane plane1 = new Plane("The plane #1");
Plane plane2 = new Plane("The plane #2");
Plane plane3 = new Plane("The plane #3");
}
private static void waiting() {
//write your code here
try {
Thread.sleep(100);
}
catch(InterruptedException e){
}
}
private static void takeOff() {
//fix this method
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
}
public static class Plane extends Thread {
public Plane(String name) {
super(name);
start();
}
public void run() {
boolean isAlreadyTakenOff = false;
while (!isAlreadyTakenOff) {
if (RUNWAY.trySetTakingOffPlane(this)) { // if the runway is available, we'll take it
System.out.println(getName() + " is flying");
takeOff();// is flying
System.out.println(getName() + " in the sky");
isAlreadyTakenOff = true;
RUNWAY.setTakingOffPlane(null);
} else if (!this.equals(RUNWAY.getTakingOffPlane())) { // if the runway is occupied by a plane
System.out.println(getName() + " is waiting");
waiting(); // is waiting
}
}
}
}
public static class Runway {
private Thread t;
public Thread getTakingOffPlane() {
return t;
}
public void setTakingOffPlane(Thread t) {
synchronized (this) {
this.t = t;
}
}
public boolean trySetTakingOffPlane(Thread t) {
synchronized (this) {
if (this.t == null) {
this.t = t;
return true;
}
return false;
}
}
}
}