-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuelTank.java
More file actions
74 lines (60 loc) · 1.23 KB
/
fuelTank.java
File metadata and controls
74 lines (60 loc) · 1.23 KB
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
package semesterProject;
public class fuelTank extends Thread{
double fuel;
Airplane plane;
double capacity;
private boolean running;
fuelTank(){
this.fuel = 500;
this.capacity = 1000;
}
void updateFuel(){
this.fuel--;
}
public void setPlane(Airplane plane) {
this.plane = plane;
}
void refill(double fuel) {
if(!plane.checkStatus()) {
if((this.fuel+fuel)<capacity) {
if(fuel>0) {
this.fuel += fuel;
}
else {
System.out.println("Fuel Shoul be more than 0");
}
}
else
System.out.println("Fuel can not be more than Capacity of tank");
}
else
System.out.println("No refill in Mid Air");
}
void displayFuel() {
System.out.println("Fuel is " + fuel);
}
void startMeter() {
running=true;
}
void stopMeter() {
running=false;
}
public void run() {
try {
while(true) {
if(plane.checkStatus() && running) {
displayFuel();
updateFuel();
Thread.sleep(4000);
}
else if(!running && !plane.checkStatus()) {
displayFuel();
Thread.sleep(5000);
}
}
}
catch (InterruptedException e) {
System.out.println(" Display Fuel stopped.");
}
}
}