-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
118 lines (93 loc) · 3.75 KB
/
Main.java
File metadata and controls
118 lines (93 loc) · 3.75 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package semesterProject;
import java.util.Scanner;
public class Main {
static void menu() {
System.out.println("\n\tSelect from Option below:");
System.out.println("1\tTake Off");
System.out.println("2\tLand");
System.out.println("3\tCheck Fuel");
System.out.println("4\tDetails");
System.out.println("5\tExit");
System.out.print("Enter Choice: ");
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter Name: ");
String name = sc.nextLine();
System.out.print("Enter Passenger Capacity: ");
int passenger = sc.nextInt();
sc.nextLine();
Engine engine = new Engine();
Navigation nav = new Navigation();
Airplane myplane = new Airplane(name, passenger, engine, nav);
fuelTank tank = myplane.tank;
Cockpit cockpit = myplane.cockpit;
myplane.setNavigation(nav);
int choice;
do {
menu();
while (!sc.hasNextInt()) {
sc.nextLine();
System.out.println("Please enter a valid number.");
}
choice = sc.nextInt();
sc.nextLine();
switch (choice) {
case 1:
if (!myplane.checkStatus()) {
nav.input();
myplane.cockpit.takeOff();
try {
if (!nav.isAlive()) nav.start();
if (!tank.isAlive()) tank.start();
} catch (IllegalThreadStateException e) {
System.err.println("Thread Dead : 9/11 Successfull");
}
} else {
System.out.println("Plane is already in the air!");
}
break;
case 2:
if (myplane.checkStatus()) {
myplane.cockpit.land();
nav.stopNav();
} else {
System.out.println("Plane is already on the ground.");
}
break;
case 3:
if (!myplane.checkStatus()) {
tank.displayFuel();
System.out.print("Refill? (y/n): ");
String c = sc.nextLine().trim().toLowerCase();
if (c.equals("y")) {
System.out.print("Amount: ");
while (!sc.hasNextDouble()) {
sc.nextLine();
System.out.print("Enter a number: ");
}
double amt = sc.nextDouble();
sc.nextLine();
tank.refill(amt);
tank.displayFuel();
}
} else {
System.out.println("Refill While Flying ??");
}
break;
case 4:
System.out.println(myplane);
break;
case 5:
System.out.println("Exiting...");
nav.interrupt();
tank.interrupt();
break;
default:
System.out.println("Invalid option.");
break;
}
} while (choice != 5);
sc.close();
}
}