-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAirReservation.java
364 lines (340 loc) · 12.9 KB
/
AirReservation.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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
import java.util.*;
import java.lang.*;
class Plane
{
String destination;
int id;
Double time;
Plane(int id,Double time,String destination)
{
this.destination = destination;
this.time = time;
this.id = id;
}
}
class CargoPlane extends Plane
{
int i=0;
Double w=0.00,weight,r;
CargoPlane(String destination,int id,Double time,Double weight)
{
super(id, time, destination);
this.weight = weight;
}
Double available_space()
{
r = weight-w;
return r;
}
void Add_package(Double wt)
{
if(w <= weight)
{
i=i+1;
w = w + wt;
System.out.println("your package has been added successfully\n");
System.out.println("Receipt no: "+i);
}
else
{
System.out.println("sorry there is no space ");
}
}
Double get_time()
{
return time;
}
int get_id()
{
return id;
}
void Display()
{
System.out.println("\nSource: Mumbai\t Destination: "+destination);
System.out.println("\nFlight Id No: "+id+"\tDeparture Time: "+time);
r= weight - w;
System.out.println("Available space: "+r);
}
}
class Flight extends Plane
{
int flag=0,i=0,j=0,price_firstseat,price_Economyseat;
Flight (String destination,int id,Double time)
{
super(id, time, destination);
}
boolean [] seating = new boolean[11];
Scanner input = new Scanner(System.in);
public int makeReservation(int price_firstseat,int price_Economyseat)
{
System.out.println("Please type 1 for First Class or 2 for Economy: ");
int section = input.nextInt();
if ( section == 1 )
{
firstClassSeat();
return price_firstseat;
}
else
{
economySeat();
return price_Economyseat;
}
}
public void firstClassSeat()
{
for ( int count = 1; count <= 5; count++ )
{
if ( seating[count] == false )
{
seating[count] = true;
System.out.println("------------------------------------------------------------------------------------------");
System.out.printf("First Class. Seat# %d\n", count);
i++;
break;
}
else if ( seating[5] == true )
{
if ( seating[10] == true)
{
System.out.println("Sorry, flight fully booked. Next flight is in 3 hours.");
}
else
{
System.out.println("First Class is fully booked. Would you like Economy? 1 for Yes 2 for No");
int choice = input.nextInt();
if ( choice == 1 )
{
economySeat();
}
}
}
}
}
public void economySeat()
{
for ( int count = 6; count <= 10; count++ )
{
if ( seating[count] == false )
{
seating[count] = true;
System.out.println("------------------------------------------------------------------------------------------");
System.out.printf("Economy. Seat# %d\n", count);
j++;
break;
}
else if ( seating[10] == true )
{
if ( seating[5] == true)
{
System.out.println("Sorry, flight fully booked.");
System.exit(0);
}
else
{
System.out.println("Economy is fully booked. Would you like First Class? 1 for Yes 2 for No");
int choice = input.nextInt();
if ( choice == 1 )
{
firstClassSeat();
}
}
}
}
}
Double get_time()
{
return time;
}
int get_id()
{
return id;
}
int seatcheck()
{
if(seating[5]==true && seating[10]==true)
{
flag=1;
}
return flag;
}
void Display()
{
System.out.println("\nSource: Mumbai\t Destination: "+destination);
System.out.println("\nFlight Id No: "+id+"\tDeparture Time: "+time);
System.out.println("total no of seats booked in first class:"+i);
System.out.println("total no of seats booked in Economy class:"+j);
}
}
class Airline
{
Vector <Flight> FlightList = new Vector<>();
Vector <CargoPlane> cargolist = new Vector<>();
}
class Passenger
{
String name,emailid;
int age;
Passenger(String name,String emailid,int age)
{
this.name=name;
this.age=age;
this.emailid=emailid;
}
void display()
{
System.out.println("Name: "+name+"\tAge: "+age);
}
}
public class AirReservation
{
public static void main(String[] args)
{
Double time=0.00,b,u,d,r=0.00;
String choice,name,emailid,password="dishank",pass,m;
int book,k,j,age,q=1,id=0,i=1,x,y,z,price=0,o=0,c;
Airline AirIndia = new Airline();
Flight f1 = new Flight("delhi",2447,17.25);
Flight f2 = new Flight("kanpur",2007,3.30);
Flight f3 = new Flight("kerala",2769,22.28);
CargoPlane c1 = new CargoPlane("nepal",1967,5.30,1000.00);
CargoPlane c2 = new CargoPlane("europe", 1456,7.49,1000.00);
AirIndia.FlightList.add(f1);
AirIndia.FlightList.add(f3);
AirIndia.FlightList.add(f2);
AirIndia.cargolist.add(c1);
AirIndia.cargolist.add(c2);
x=f1.seatcheck();
y=f2.seatcheck();
z=f3.seatcheck();
u = c1.available_space();
d = c2.available_space();
while(x!=1 && y!=1 && z!=1 && u>0 && d>=0)
{
Scanner s1 = new Scanner(System.in);
System.out.println("enter 1 for administrator\t2 for passenger\t 3 to add package in cargo plane");
k=s1.nextInt();
if(k==2)
{
System.out.println("\nWelcome to AirIndia ticket Reservation System\n");
System.out.println("\nEnter no of tickects you want to book\n");
book = s1.nextInt();
for(j=1;i<=book;j++)
{
Scanner s = new Scanner(System.in);
System.out.println("\nEnter your Name,Age and Email id\n");
name = s.nextLine();
age = s.nextInt();
emailid= s.next();
Passenger pi = new Passenger(name,emailid,age);
System.out.println("choose your destination\n kerala\n delhi\n kanpur\n");
choice = s.next();
switch(choice)
{
case "kerala": price = f3.makeReservation(5999,3101);
time = f3.get_time();
id = f3.get_id();
choice="kerala";
break;
case "delhi" :
price = f1.makeReservation(7696,5569);
time = f1.get_time();
id = f1.get_id();
choice="delhi" ;
break;
case "kanpur":
price = f2.makeReservation(3259,2329);
time = f2.get_time();
id = f2.get_id();
choice="kanpur";
break;
default:
System.out.println("enter correct destination\n");
break;
}
if(choice=="kerala"||choice=="delhi"||choice=="kanpur")
{
o=o+price;
pi.display();
System.out.println("\nSource: Mumbai\t Destination: "+choice);
i++;
System.out.println("\nFlight Id No: "+id+"\tDeparture Time: "+time);
System.out.println("\nFare:"+price);
System.out.println("------------------------------------------------------------------------------------------");
}
}
}
else if(k==3 )
{
System.out.println("welcome to Air India post services\n");
System.out.println("enter weight of the parcel");
b = s1.nextDouble();
if(b<=100)
{
System.out.println("Enter Destination\nnepal\neurope");
m = s1.next();
switch(m)
{
case "nepal":
u = c1.available_space();
System.out.println("\nAvailable space: "+u);
c1.Add_package(b);
time = c1.get_time();
id = c1.get_id();
r = b*4;
break;
case "europe":
u = c2.available_space();
System.out.println("\nAvailable space: "+u);
c2.Add_package(b);
time = c2.get_time();
id = c2.get_id();
r = b*9;
break;
default:
System.out.println("\nenter correct destination");
break;
}
System.out.println("\nSource: Mumbai\t Destination: "+m);
System.out.println("\nweight of the courier: "+b);
System.out.println("\nFlight Id No: "+id+"\tDeparture Time: "+time);
System.out.println("\nAmount:"+r);
}
else
{
System.out.println("\nMaximum capacity of the parcel is 100 kgs\n");
}
}
else
{
System.out.println("enter password\n");
pass = s1.next();
if(pass.equals(password))
{
System.out.println("welcome\n");
System.out.println("enter\n1 to see the passenger flight list\n2 to see cargo plane list\n3 for money collected");
c = s1.nextInt();
switch(c)
{
case 1:
f1.Display();
System.out.println("\n");
f2.Display();
System.out.println("\n");
f3.Display();
System.out.println("\n");
break;
case 2:
c1.Display();
System.out.println("\n");
c2.Display();
System.out.println("\n");
break;
case 3 :
System.out.println("total money:"+o);
break;
}
}
}
}
}
}