-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAirTrafficController.java
93 lines (68 loc) · 1.83 KB
/
AirTrafficController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package Solutions;
class ATCMediator implements IATCMediator {
private Flight flight;
private Runway runway;
public boolean land;
public void registerRunway(Runway runway) {
this.runway = runway;
}
public void registerFlight(Flight flight) {
this.flight = flight;
}
public boolean isLandingOk() {
return land;
}
@Override
public void setLandingStatus(boolean status) {
land = status;
}
}
interface Command {
void land();
}
interface IATCMediator {
public void registerRunway(Runway runway);
public void registerFlight(Flight flight);
public boolean isLandingOk();
public void setLandingStatus(boolean status);
}
class Flight implements Command {
private IATCMediator atcMediator;
public Flight(IATCMediator atcMediator) {
this.atcMediator = atcMediator;
}
public void land() {
if (atcMediator.isLandingOk()) {
System.out.println("Landing done....");
atcMediator.setLandingStatus(true);
} else
System.out.println("Will wait to land....");
}
public void getReady() {
System.out.println("Getting ready...");
}
}
class Runway implements Command {
private IATCMediator atcMediator;
public Runway(IATCMediator atcMediator) {
this.atcMediator = atcMediator;
atcMediator.setLandingStatus(true);
}
@Override
public void land() {
System.out.println("Landing permission granted...");
atcMediator.setLandingStatus(true);
}
}
public class AirTrafficController {
public static void main(String[] args) {
IATCMediator atcMediator = new ATCMediator();
Flight sparrow101 = new Flight(atcMediator);
Runway mainRunway = new Runway(atcMediator);
atcMediator.registerFlight(sparrow101);
atcMediator.registerRunway(mainRunway);
sparrow101.getReady();
mainRunway.land();
sparrow101.land();
}
}