Skip to content

Commit c5cf584

Browse files
committed
Code updated
1 parent 02e7016 commit c5cf584

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

AirTrafficController/src/AirTrafficControl.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public void getChoice() {
5454
runWays.forEach(System.out::println);
5555
break;
5656
case 5:
57+
System.out.println("Exiting...");
5758
System.exit(0);
5859
}
5960
}
@@ -64,18 +65,20 @@ private void getAndAllocate() {
6465
Flight getFlight =
6566
flights.stream().filter(f -> f.flightName.equals(flightName)).findFirst().orElse(null);
6667
if (getFlight != null) {
67-
System.out.println("Enter weight of flight(in tons):");
68-
flightWeight = sc.nextInt();
69-
compTime = getFlight.computeTime(flightWeight);
70-
checkAndAssignRunWay();
68+
if (!getFlight.isRunwayAllocated){
69+
System.out.println("Enter weight of flight(in tons):");
70+
flightWeight = sc.nextInt();
71+
compTime = getFlight.computeTime(flightWeight);
72+
checkAndAssignRunWay(getFlight);
73+
} else System.out.println("--> Runway already allocated for this flight\n");
7174
} else System.out.println("Flight doesn't authorised");
7275
}
7376

74-
public void checkAndAssignRunWay() {
77+
public void checkAndAssignRunWay(Flight selectedFlight) {
7578
RunWay selectedRunWay =
7679
runWays.stream().filter(r -> compTime <= r.time && r.status).findFirst().orElse(null);
7780
if (selectedRunWay != null) {
78-
Request r = new Request(flightName, flightWeight, cho, compTime, selectedRunWay);
81+
Request r = new Request(flightName, flightWeight, cho, compTime, selectedRunWay, selectedFlight);
7982
r.start();
8083
try {
8184
Thread.sleep(500);

AirTrafficController/src/Flight.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ class Flight {
22
String flightName;
33
int maxWeight;
44
int allottedTime;
5+
boolean isRunwayAllocated = false;
56

67
Flight(String fName, int maxWeight, int timeHalt) {
78
this.flightName = fName;

AirTrafficController/src/Request.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,21 @@ class Request extends Thread {
55

66
String type;
77
RunWay runWay;
8+
Flight allottedFlight;
89

9-
public Request(String aName, int weightA, String cho, int compTime, RunWay rw) {
10-
this.requestedFlight = aName;
11-
this.flightWeight = weightA;
12-
this.runWay = rw;
13-
this.coolTime = compTime;
14-
this.type = cho;
10+
public Request(String flightName, int weight, String requestType, int coolTime, RunWay runWay, Flight selectedFlight) {
11+
this.requestedFlight = flightName;
12+
this.flightWeight = weight;
13+
this.runWay = runWay;
14+
this.coolTime = coolTime;
15+
this.type = requestType;
16+
this.allottedFlight = selectedFlight;
1517
}
1618

1719
public void run() {
1820
runWay.status = false;
21+
runWay.allottedFlight = allottedFlight;
22+
allottedFlight.isRunwayAllocated = true;
1923
try {
2024
System.out.println(
2125
"---------------------------------------------------------------------------------");
@@ -28,6 +32,8 @@ public void run() {
2832
"---------------------------------------------------------------------------------");
2933
Thread.sleep(1000L * coolTime);
3034
runWay.status = true;
35+
runWay.allottedFlight = null;
36+
allottedFlight.isRunwayAllocated = false;
3137
} catch (Exception ignored) {
3238
}
3339
}

AirTrafficController/src/RunWay.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ class RunWay {
33
int time;
44
boolean status;
55

6+
Flight allottedFlight;
7+
68
RunWay(String name, int time, boolean status) {
79
this.name = name;
810
this.time = time;
911
this.status = status;
12+
this.allottedFlight = null;
1013
}
1114

1215
@Override

0 commit comments

Comments
 (0)