forked from shrishti2410/FlightLogisticsSystem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FlightLogisticsSystem_finall.java
1247 lines (1118 loc) · 54.4 KB
/
FlightLogisticsSystem_finall.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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
DSA PROJECT :
AirEase: A Flight Logistics System
By : UCE2023615
UCE2023609
UCE2023607
UCE2023604
Problem Statement :
AirEase aims to simplify the airline management process by providing a user-friendly system for both travelers and administrators.
The system will allow users to search for and book flights based on minimum cost or shortest travel distance between cities,
facilitating quick decision-making for travelers.
Admins can access a dedicated interface to manage flight bookings, reschedule flights based on real-time weather data,
and ensure a seamless experience for users despite weather disruptions.
This dual-interface system will be built to handle the complexities of real-world logistics with efficient data structures and algorithms.
*/
import java.io.BufferedReader;
import java.util.*;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
class WeatherService {
private static final String API_KEY = "ba45b9824ab3e00ac24a08b49cd9e93b"; // Ensure there are no leading or trailing spaces
private static final String BASE_URL = "https://api.openweathermap.org/data/2.5/weather?q=";
public static String getWeatherForCity(String cityName) {
try {
// URL encode the city name to handle spaces and special characters
String encodedCityName = URLEncoder.encode(cityName, StandardCharsets.UTF_8.toString());
String urlString = BASE_URL + encodedCityName + "&appid=" + API_KEY + "&units=metric";
URL url = new URL(urlString);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder response = new StringBuilder();
String line;
while ((line = in.readLine()) != null) {
response.append(line);
}
in.close();
return parseWeatherData(response.toString());
} catch (Exception e) {
e.printStackTrace();
return "Could not fetch weather data.";
}
}
// Add these parameters to the parsing function
private static String parseWeatherData(String jsonResponse) {
JsonObject jsonObject = JsonParser.parseString(jsonResponse).getAsJsonObject();
JsonObject main = jsonObject.getAsJsonObject("main");
JsonObject weather = jsonObject.getAsJsonArray("weather").get(0).getAsJsonObject();
JsonObject wind = jsonObject.getAsJsonObject("wind");
double temperature = main.get("temp").getAsDouble();
String description = weather.get("description").getAsString();
int humidity = main.get("humidity").getAsInt();
double windSpeed = wind.get("speed").getAsDouble() * 3.6; // Convert from m/s to km/h
int windDegree = wind.get("deg").getAsInt(); // Wind direction
double visibility = jsonObject.has("visibility") ? jsonObject.get("visibility").getAsDouble() : 10000; // Visibility in meters (default to 10 km)
// Safety check criteria
boolean isSafe = true;
StringBuilder message = new StringBuilder();
if (windSpeed > 50) {
isSafe = false;
message.append("High wind speeds detected. Flights may be rescheduled. ");
}
if (visibility < 2000) {
isSafe = false;
message.append("Low visibility detected. Flights may be rescheduled. ");
}
if (description.toLowerCase().contains("thunderstorm") || description.toLowerCase().contains("snow")) {
isSafe = false;
message.append("Adverse weather conditions detected (thunderstorms, snow). Flights may be rescheduled. ");
}
// Default message for safe conditions
if (isSafe) {
message.append("Arrivals and departures are likely safe.");
} else {
message.append("Conditions indicate potential delays or rescheduling.");
}
// Return weather details along with the safety message
return String.format("Temperature: %.1f°C, Condition: %s, Humidity: %d%%, Wind Speed: %.1f km/h, Visibility: %.0f meters, Status: %s",
temperature, description, humidity, windSpeed, visibility, message.toString());
}
}
class Flight {
String airline;
String destination;
int cost;
int time;
String flightNo;
public Flight(String airline, String destination, int cost, int time, String flightNo) {
this.airline = airline;
this.destination = destination;
this.cost = cost;
this.time = time;
this.flightNo = flightNo;
}
}
class Node {
String city;
int cost;
int time;
List<Flight> path;
public Node(String city, int cost, int time, List<Flight> path) {
this.city = city;
this.cost = cost;
this.time = time;
this.path = new ArrayList<>(path);
}
}
class FlightLogisticsSystem {
static Map<String, List<Flight>> flightsGraph = new HashMap<>(); // Adjacency list for storing flights between cities
static List<String> badWeatherCities = new ArrayList<>(); //Stores cities with bad weather
// Adds a flight to the graph if weather is safe at both source and destination
public static void addFlight(String source, String destination, String airline, int cost, int time, String flightNo) {
if(WeatherService.getWeatherForCity(source).contains("safe") && WeatherService.getWeatherForCity(destination).contains("safe")) {
flightsGraph.putIfAbsent(source, new ArrayList<>());
flightsGraph.get(source).add(new Flight(airline, destination, cost, time,flightNo));
}else{
//Adds cities with rescheduled flights to the bad weather list
if(WeatherService.getWeatherForCity(source).contains("rescheduled") && !badWeatherCities.contains(source)) {
badWeatherCities.add(source);
}
if(WeatherService.getWeatherForCity(destination).contains("rescheduled") && !badWeatherCities.contains(destination)){
badWeatherCities.add(destination);
}
}
}
// method to remove a specific flight
public static void removeFlight(String source, String destination, String airline, int cost, int time, String flightNo) {
List<Flight> flights = flightsGraph.getOrDefault(source, new ArrayList<>());
flights.removeIf(flight -> flight.destination.equals(destination) && flight.airline.equals(airline) &&
flight.cost == cost && flight.time == time && flight.flightNo.equals(flightNo));
System.out.println("Flight removed successfully!");
}
// Finds the cheapest route from src to dest using Dijkstra's algorithm based on cost
public static void findCheapestFlight(String src, String dest) {
PriorityQueue<Node> pq = new PriorityQueue<>(Comparator.comparingInt(a -> a.cost));
Map<String, Integer> minCost = new HashMap<>();
pq.add(new Node(src, 0, 0, new ArrayList<>()));
minCost.put(src, 0);
while (!pq.isEmpty()) {
Node currentNode = pq.poll();
String currentCity = currentNode.city;
int costSoFar = currentNode.cost;
// If destination is reached, print details and return
if (currentCity.equals(dest)) {
System.out.println("Minimum cost to " + dest + " is " + costSoFar + " with time " + currentNode.time + " minutes.");
System.out.println("Flights to take:");
String tempCity = src; // Set the starting city for the output
for (Flight flight : currentNode.path) {
System.out.println("Airline: " + flight.airline + ", From: " + tempCity + ", To: " + flight.destination + ", Cost: " + flight.cost + ", Time: " + flight.time + " minutes.");
tempCity = flight.destination;
}
return;
}
// Explore connected flights and update minimum cost path if a cheaper route is found
for (Flight flight : flightsGraph.getOrDefault(currentCity, new ArrayList<>())) {
int newCost = costSoFar + flight.cost;
if (newCost < minCost.getOrDefault(flight.destination, Integer.MAX_VALUE)) {
minCost.put(flight.destination, newCost);
List<Flight> newPath = new ArrayList<>(currentNode.path);
newPath.add(flight);
pq.add(new Node(flight.destination, newCost, currentNode.time + flight.time, newPath));
}
}
}
System.out.println("No route available from " + src + " to " + dest);
}
// Finds all routes from src to dest and sorts them by cost
public static void findAllFlightsSortedByCost(String src, String dest) {
List<Node> allRoutes = new ArrayList<>();
List<Flight> currentPath = new ArrayList<>();
Set<String> visited = new HashSet<>();
// DFS for finding all paths with cost tracking
dfsForCost(src, dest, 0, 0, currentPath, allRoutes, visited);
allRoutes.sort(Comparator.comparingInt(node -> node.cost));
// Print all routes if available, otherwise print no route found
if (allRoutes.isEmpty()) {
System.out.println("No routes available from " + src + " to " + dest);
} else {
System.out.println("All possible routes from " + src + " to " + dest + " sorted by cost:");
for (Node route : allRoutes) {
System.out.println("Total cost: " + route.cost + ", Total time: " + route.time + " minutes");
System.out.println("Flights to take:");
String startCity = src;
for (Flight flight : route.path) {
System.out.println("Airline: " + flight.airline + ", From: " + startCity + ", To: " + flight.destination + ", Cost: " + flight.cost + ", Time: " + flight.time + " minutes.");
startCity = flight.destination;
}
System.out.println();
}
}
}
// DFS helper method to explore all paths by cost
private static void dfsForCost(String currentCity, String dest, int currentCost, int currentTime, List<Flight> currentPath, List<Node> allRoutes, Set<String> visited) {
if (currentCity.equals(dest)) {
allRoutes.add(new Node(currentCity, currentCost, currentTime, new ArrayList<>(currentPath)));
return;
}
visited.add(currentCity);
for (Flight flight : flightsGraph.getOrDefault(currentCity, new ArrayList<>())) {
if (!visited.contains(flight.destination)) {
currentPath.add(flight); // Add flight to the current path
dfsForCost(flight.destination, dest, currentCost + flight.cost, currentTime + flight.time, currentPath, allRoutes, visited);
currentPath.remove(currentPath.size() - 1); // Remove flight after DFS call
}
}
visited.remove(currentCity);
}
// Finds the fastest route from src to dest using Dijkstra's algorithm based on time
public static void findFastestFlight(String src, String dest) {
PriorityQueue<Node> pq = new PriorityQueue<>(Comparator.comparingInt(a -> a.time));
Map<String, Integer> minTime = new HashMap<>();
pq.add(new Node(src, 0, 0, new ArrayList<>()));
minTime.put(src, 0);
while (!pq.isEmpty()) {
Node currentNode = pq.poll();
String currentCity = currentNode.city;
int timeSoFar = currentNode.time;
// If destination is reached, print details and return
if (currentCity.equals(dest)) {
System.out.println("Minimum time to " + dest + " is " + timeSoFar + " minutes with cost " + currentNode.cost);
System.out.println("Flights to take:");
String tempCity = src; // Set the starting city for the output
for (Flight flight : currentNode.path) {
System.out.println("Airline: " + flight.airline + ", From: " + tempCity + ", To: " + flight.destination + ", Cost: " + flight.cost + ", Time: " + flight.time + " minutes.");
tempCity = flight.destination;
}
return;
}
// Explore connected flights and update minimum time path if a faster route is found
for (Flight flight : flightsGraph.getOrDefault(currentCity, new ArrayList<>())) {
int newTime = timeSoFar + flight.time;
if (newTime < minTime.getOrDefault(flight.destination, Integer.MAX_VALUE)) {
minTime.put(flight.destination, newTime);
List<Flight> newPath = new ArrayList<>(currentNode.path);
newPath.add(flight);
pq.add(new Node(flight.destination, currentNode.cost + flight.cost, newTime, newPath));
}
}
}
System.out.println("No route available from " + src + " to " + dest);
}
// Finds all routes from src to dest sorted by travel time
public static void findAllFlightsSortedByTime(String src, String dest) {
List<Node> allRoutes = new ArrayList<>();
List<Flight> currentPath = new ArrayList<>();
Set<String> visited = new HashSet<>();
// DFS for finding all paths with time tracking
dfsByTime(src, dest, 0, 0, currentPath, allRoutes, visited);
allRoutes.sort(Comparator.comparingInt(node -> node.time));
// Print all routes if available, otherwise print no route found
if (allRoutes.isEmpty()) {
System.out.println("No routes available from " + src + " to " + dest);
} else {
System.out.println("All possible routes from " + src + " to " + dest + " sorted by time:");
for (Node route : allRoutes) {
System.out.println("Total time: " + route.time + " minutes, Total cost: " + route.cost);
System.out.println("Flights to take:");
String startCity = src;
for (Flight flight : route.path) {
System.out.println("Airline: " + flight.airline + ", From: " + startCity + ", To: " + flight.destination + ", Cost: " + flight.cost + ", Time: " + flight.time + " minutes.");
startCity = flight.destination;
}
System.out.println();
}
}
}
// DFS method to explore all paths by time
private static void dfsByTime(String currentCity, String dest, int currentCost, int currentTime, List<Flight> currentPath, List<Node> allRoutes, Set<String> visited) {
if (currentCity.equals(dest)) {
allRoutes.add(new Node(currentCity, currentCost, currentTime, new ArrayList<>(currentPath)));
return;
}
visited.add(currentCity);
for (Flight flight : flightsGraph.getOrDefault(currentCity, new ArrayList<>())) {
if (!visited.contains(flight.destination)) {
currentPath.add(flight);
dfsByTime(flight.destination, dest, currentCost + flight.cost, currentTime + flight.time, currentPath, allRoutes, visited);
currentPath.remove(currentPath.size() - 1);
}
}
visited.remove(currentCity);
}
// Method to find and display direct flights between two cities
public static void FlightsWithoutLayovers(String src, String dest) {
boolean directFound = false;
// Iterate through all flights from the source city
for (Flight flight : flightsGraph.getOrDefault(src, new ArrayList<>())) {
if (flight.destination.equals(dest)) {
System.out.println("Direct flight found: Airline: " + flight.airline + ", Cost: " + flight.cost + ", Time: " + flight.time + " minutes.");
directFound = true;
}
}
if(!directFound){
System.out.println("No direct flight between "+src+ " and "+dest);
}
}
public static void main(String[] args) {
System.out.println("Welcome to AirEase - Your Ultimate Flight Logistics Companion!");
System.out.println("Effortlessly manage flights, track routes, and ensure a smooth journey for passengers and cargo alike. From real-time updates to optimized routing, AirEase is here to make airline management simpler and more efficient.");
System.out.println("Fasten your seatbelt, and let’s get started!");
System.out.println("We appreciate your patience while we are fetching real-time weather data to ensure your journey is safe and free of turbulent weather. ");
addFlight("Chennai", "Delhi", "Spice Jet", 10000, 180, "SG801");
addFlight("Chennai", "Kolkata", "Air India", 6000, 120,"AI801");
addFlight("Delhi", "Kolkata", "Air India", 6000, 150,"AI802");
addFlight("Delhi", "Mumbai", "Indigo", 6000, 120,"6E801");
addFlight("Delhi", "Pune", "Air India", 8000, 120,"AI803");
addFlight("Delhi", "Hyderabad", "Indigo", 7000, 180,"6E802");
addFlight("Kolkata", "Bangalore", "Air India", 6000, 120,"AI804");
addFlight("Kolkata", "Hyderabad", "Indigo", 7000, 90,"6E803");
addFlight("Bhubaneswar", "Mumbai", "Air India", 6000, 150,"AI805");
addFlight("Bhubaneswar", "Kolkata", "Indigo", 5000, 90,"6E804");
addFlight("Jaipur", "Kolkata", "Air India", 6000, 90,"AI806");
addFlight("Jaipur", "Bhopal", "Indigo", 5000, 60,"6E805");
addFlight("Bhopal", "Hyderabad", "Spice Jet", 5000, 120,"SG802");
addFlight("Bhopal", "Mumbai", "Spice Jet", 7000, 120,"SG803");
addFlight("Mumbai", "Delhi", "Spice Jet", 5000, 120,"SG804");
addFlight("Mumbai", "Bhopal", "Air India", 4000, 120,"AI807");
addFlight("Mumbai", "Jaipur", "Indigo", 5000, 90,"6E806");
addFlight("Mumbai", "Delhi", "Air India", 8000, 120,"AI808");
addFlight("Mumbai", "Bhopal", "Indigo", 3000, 120,"6E807");
addFlight("Mumbai", "Jaipur", "Air India", 7000, 90,"AI809");
addFlight("Pune", "Hyderabad", "Spice Jet", 5000, 120,"SG805");
addFlight("Pune", "Bangalore", "Air India", 6000, 120,"AI810");
addFlight("Pune", "Hyderabad", "Air India", 5000, 120,"AI810");
addFlight("Pune", "Bangalore", "Spice Jet", 3000, 120,"SG806");
addFlight("Pune", "Mumbai", "Indigo", 2000, 20,"6E808");
addFlight("Hyderabad", "Delhi", "Spice Jet", 7000, 150,"SG806");
addFlight("Hyderabad", "Bangalore", "Air India", 3000, 45,"AI811");
addFlight("Hyderabad", "Chennai", "Indigo", 2000, 45,"6E809");
addFlight("Bangalore", "Bhubaneswar", "Spice Jet", 7000, 75,"SG807");
addFlight("Bangalore", "Mumbai", "Air India", 7000, 90,"AI812");
addFlight("Bangalore", "Delhi", "Indigo", 5000, 120,"6E810");
System.out.println("Enter 1 to execute admin functionality \n 2 to execute user functionality \n 3 to exit");
Scanner sc = new Scanner(System.in);
int adminOrUser;
do {
System.out.println("Enter 1 to execute admin functionality and 2 to execute user functionality. Enter 3 to exit.");
adminOrUser = sc.nextInt();
sc.nextLine(); // Consume newline
switch (adminOrUser) {
case 1:
handleAdminFunctionality();
break;
case 2:
handleUserFunctionality();
break;
case 3:
System.out.println("Exiting application.");
break;
default:
System.out.println("Invalid option! Please enter 1 for admin or 2 for user functionality, or 3 to exit.");
}
} while (adminOrUser != 3);
}
// Admin functionality for adding or removing flights
private static void handleAdminFunctionality() {
Scanner sc = new Scanner(System.in);
int ch;
do {
System.out.println("Admin Menu: \n1. Add flight\n2. Remove flight\n3. Return to main menu");
ch = sc.nextInt();
sc.nextLine(); // Consume newline
String src, dest, airline, flightNo;
int cost, time;
switch (ch) {
case 1:
System.out.println("Enter source city:");
src = sc.nextLine();
System.out.println("Enter destination city:");
dest = sc.nextLine();
if (badWeatherCities.contains(src)) {
System.out.println("Sorry no flights available due to bad weather. Details of the weather are as follows: ");
System.out.println(WeatherService.getWeatherForCity(src));
return;
}
if (badWeatherCities.contains(dest)) {
System.out.println("Sorry no flights available due to bad weather. Details of the weather are as follows: ");
System.out.println(WeatherService.getWeatherForCity(dest));
return;
}
System.out.println("Enter airline:");
airline = sc.nextLine();
System.out.println("Enter cost:");
cost = sc.nextInt();
System.out.println("Enter time:");
time = sc.nextInt();
sc.nextLine(); // Consume newline
System.out.println("Enter flight number:");
flightNo = sc.nextLine();
addFlight(src, dest, airline, cost, time, flightNo);
break;
case 2:
// Gather flight details for removing an existing flight
System.out.println("Enter source city:");
src = sc.nextLine();
System.out.println("Enter destination city:");
dest = sc.nextLine();
System.out.println("Enter airline:");
airline = sc.nextLine();
System.out.println("Enter cost:");
cost = sc.nextInt();
System.out.println("Enter time:");
time = sc.nextInt();
sc.nextLine(); // Consume newline
System.out.println("Enter flight number:");
flightNo = sc.nextLine();
removeFlight(src, dest, airline, cost, time, flightNo);
break;
case 3:
System.out.println("Returning to main menu.");
break;
default:
System.out.println("Invalid option! Please choose a valid option from the Admin Menu.");
}
} while (ch != 3);
}
// User functionality for finding flights and booking
private static void handleUserFunctionality() {
Scanner sc = new Scanner(System.in);
int choice;
do {
System.out.println("User Menu: \n1. Minimum cost\n2. All possible routes sorted by cost\n3. Minimum time\n4. All possible routes sorted by time\n5. Flights with/without layovers\n6. Return to main menu");
choice = sc.nextInt();
sc.nextLine(); // Consume newline
if (choice == 6) {
System.out.println("Returning to main menu.");
break;
}
System.out.println("Enter source city: ");
String source = sc.nextLine();
if (badWeatherCities.contains(source)) {
System.out.println("Sorry no flights available due to bad weather. Details of the weather are as follows: ");
System.out.println(WeatherService.getWeatherForCity(source));
return;
}
System.out.println("Enter destination city: ");
String destination = sc.nextLine();
if (badWeatherCities.contains(destination)) {
System.out.println("Sorry no flights available due to bad weather. Details of the weather are as follows: ");
System.out.println(WeatherService.getWeatherForCity(destination));
return;
}
switch (choice) {
case 1:
findCheapestFlight(source, destination);
break;
case 2:
findAllFlightsSortedByCost(source, destination);
break;
case 3:
findFastestFlight(source, destination);
break;
case 4:
findAllFlightsSortedByTime(source, destination); // Implement this method
break;
case 5:
FlightsWithoutLayovers(source, destination); // Implement this method
break;
default:
System.out.println("Invalid option!");
continue;
}
System.out.println("Do you want to proceed to booking now? Enter Y for yes or N for no");
String proceedToBooking = sc.nextLine();
if (proceedToBooking.equalsIgnoreCase("Y")) {
User.booking(); // Ensure the booking functionality is implemented in User class
} else if (proceedToBooking.equalsIgnoreCase("N")) {
System.out.println("Returning to main menu.");
} else {
System.out.println("Invalid entry! Returning to main menu.");
}
} while (choice != 6);
}
}
class User {
static String name;
static long mobileNo;
static int age;
static String emailId;
public static void user_details(int noOfPassengers) {//taking details of customer
while (noOfPassengers != 0) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the name of customer");
name = sc.nextLine();
System.out.println("Enter the age");
age = sc.nextInt();
System.out.println("Enter the mobileNo");
mobileNo = sc.nextLong();
System.out.println("Enter the email Id");
emailId = sc.next();
if (emailId.contains("@")) {
System.out.println("Valid E mail Id");
} else {
System.out.println("Invalid Email Id");
}
//USE OF WHILE LOOP TILL THE USER ENTERS VALID EMAIL
while (!emailId.contains("@")) {
System.out.println("Enter the valid Email (It must contain @)");
emailId = sc.next();
}
if (emailId.contains("@")) {
System.out.println("Thank You!");
}
noOfPassengers--;
}
System.out.println("Your tickets have been booked successfully!" +
" We hope you have a happy and safe journey");
}
public static void booking() {
int noOfPassengers = 0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of tickets you want to book.");
int noOfTickets = sc.nextInt();
sc.nextLine();
while (noOfTickets != 0) {
System.out.println("For Booking, please enter the following details: ");
System.out.println("Enter the city FROM which you want to start your journey. ");
String source = sc.nextLine();
System.out.println("Enter the city TO which you want to end your journey. ");
String destination = sc.nextLine();
System.out.println("Enter the desired AIRLINE. ");
String airline = sc.nextLine();
if (FlightLogisticsSystem.flightsGraph.containsKey(source)) {
boolean flightFound = false;
for (Flight flight : FlightLogisticsSystem.flightsGraph.get(source)) {
if (flight.destination.equals(destination) && flight.airline.equals(airline)) {
System.out.println("Flight from source to destination of desired airline is available.");
flightFound = true;
break;
}
}
if (!flightFound) {
System.out.println("Flight from source to destination of desired airline is not available.");
}
} else {
System.out.println("Source city not found in the flight graph.");
}
char seatMatrix[][] = new char[16][10];
for (char[] row : seatMatrix) {
Arrays.fill(row, 'A');
}
for (int i = 0; i < seatMatrix.length; i++) {
seatMatrix[i][2] = ' ';
seatMatrix[i][6] = ' ';
}
for (int i = 0; i < seatMatrix[0].length; i++) {
seatMatrix[7][i] = '-'; // Separator row for Business and Economy classes
}
System.out.println("Towards the top is Business Class. Below the separator row is Economy Class.");
System.out.println("0 1 2 3 4 5 6 7 8 "); // Column indices
for (int i=0; i < seatMatrix.length; i++) {
System.out.print(i + " ");
for (int j=0; j<seatMatrix[0].length; j++) {
System.out.print(seatMatrix[i][j] + " ");
}
System.out.println();
}
System.out.println("Enter the number of passengers. ");
int passengers = sc.nextInt();
noOfPassengers = passengers;
while (passengers != 0) {
System.out.println("Enter the row number: ");
int rowNo = sc.nextInt();
System.out.println("Enter the column number: ");
int colNo = sc.nextInt();
if (rowNo == 2 || rowNo == 6 || colNo == 7) {
System.out.println("Invalid no. Program will terminate. ");
System.exit(0);
}
if (seatMatrix[rowNo][colNo] != 'B') {
seatMatrix[rowNo][colNo] = 'B';
passengers--;
System.out.println("Now seat matrix is: ");
for (int i = 0; i < seatMatrix.length; i++) {
for (int j = 0; j < seatMatrix[0].length; j++) {
System.out.print(seatMatrix[i][j] + " ");
}
System.out.println();
}
}
else {
System.out.println("That seat is already booked!");
}
}
System.out.println("Seats booked!");
noOfTickets--;
sc.nextLine(); // Clear newline after number input
}
User.user_details(noOfPassengers);
}
}
/* "D:\Program Files\Java\jdk-21\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2024.1\lib\idea_rt.jar=59236:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2024.1\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath C:\Users\Admin\IdeaProjects\weatherTrying\target\classes;C:\Users\Admin\.m2\repository\com\google\code\gson\gson\2.8.8\gson-2.8.8.jar FlightLogisticsSystem
Welcome to AirEase - Your Ultimate Flight Logistics Companion!
Effortlessly manage flights, track routes, and ensure a smooth journey for passengers and cargo alike. From real-time updates to optimized routing, AirEase is here to make airline management simpler and more efficient.
Fasten your seatbelt, and let’s get started!
We appreciate your patience while we are fetching real-time weather data to ensure your journey is safe and free of turbulent weather.
Enter 1 to execute admin functionality
2 to execute user functionality
3 to exit
Enter 1 to execute admin functionality and 2 to execute user functionality. Enter 3 to exit.
1
Admin Menu:
1. Add flight
2. Remove flight
3. Return to main menu
1
Enter source city:
Pune
Enter destination city:
Hyderabad
Enter airline:
Air India
Enter cost:
10000
Enter time:
120
Enter flight number:
6C309
Admin Menu:
1. Add flight
2. Remove flight
3. Return to main menu
3
Returning to main menu.
Enter 1 to execute admin functionality and 2 to execute user functionality. Enter 3 to exit.
2
User Menu:
1. Minimum cost
2. All possible routes sorted by cost
3. Minimum time
4. All possible routes sorted by time
5. Flights with/without layovers
6. Return to main menu
1
Enter source city:
Delhi
Sorry no flights available due to bad weather. Details of the weather are as follows:
Temperature: 23.1°C, Condition: haze, Humidity: 73%, Wind Speed: 0.0 km/h, Visibility: 1000 meters, Status: Low visibility detected. Flights may be rescheduled. Conditions indicate potential delays or rescheduling.
Enter 1 to execute admin functionality and 2 to execute user functionality. Enter 3 to exit.
2
User Menu:
1. Minimum cost
2. All possible routes sorted by cost
3. Minimum time
4. All possible routes sorted by time
5. Flights with/without layovers
6. Return to main menu
1
Enter source city:
Pune
Enter destination city:
Chennai
Minimum cost to Chennai is 7000 with time 165 minutes.
Flights to take:
Airline: Spice Jet, From: Pune, To: Hyderabad, Cost: 5000, Time: 120 minutes.
Airline: Indigo, From: Hyderabad, To: Chennai, Cost: 2000, Time: 45 minutes.
Do you want to proceed to booking now? Enter Y for yes or N for no
N
Returning to main menu.
User Menu:
1. Minimum cost
2. All possible routes sorted by cost
3. Minimum time
4. All possible routes sorted by time
5. Flights with/without layovers
6. Return to main menu
2
Enter source city:
Pune
Enter destination city:
Mumbai
All possible routes from Pune to Mumbai sorted by cost:
Total cost: 2000, Total time: 20 minutes
Flights to take:
Airline: Indigo, From: Pune, To: Mumbai, Cost: 2000, Time: 20 minutes.
Total cost: 10000, Total time: 210 minutes
Flights to take:
Airline: Spice Jet, From: Pune, To: Bangalore, Cost: 3000, Time: 120 minutes.
Airline: Air India, From: Bangalore, To: Mumbai, Cost: 7000, Time: 90 minutes.
Total cost: 13000, Total time: 210 minutes
Flights to take:
Airline: Air India, From: Pune, To: Bangalore, Cost: 6000, Time: 120 minutes.
Airline: Air India, From: Bangalore, To: Mumbai, Cost: 7000, Time: 90 minutes.
Total cost: 15000, Total time: 255 minutes
Flights to take:
Airline: Spice Jet, From: Pune, To: Hyderabad, Cost: 5000, Time: 120 minutes.
Airline: Air India, From: Hyderabad, To: Bangalore, Cost: 3000, Time: 45 minutes.
Airline: Air India, From: Bangalore, To: Mumbai, Cost: 7000, Time: 90 minutes.
Total cost: 15000, Total time: 255 minutes
Flights to take:
Airline: Air India, From: Pune, To: Hyderabad, Cost: 5000, Time: 120 minutes.
Airline: Air India, From: Hyderabad, To: Bangalore, Cost: 3000, Time: 45 minutes.
Airline: Air India, From: Bangalore, To: Mumbai, Cost: 7000, Time: 90 minutes.
Total cost: 16000, Total time: 345 minutes
Flights to take:
Airline: Spice Jet, From: Pune, To: Bangalore, Cost: 3000, Time: 120 minutes.
Airline: Spice Jet, From: Bangalore, To: Bhubaneswar, Cost: 7000, Time: 75 minutes.
Airline: Air India, From: Bhubaneswar, To: Mumbai, Cost: 6000, Time: 150 minutes.
Total cost: 19000, Total time: 345 minutes
Flights to take:
Airline: Air India, From: Pune, To: Bangalore, Cost: 6000, Time: 120 minutes.
Airline: Spice Jet, From: Bangalore, To: Bhubaneswar, Cost: 7000, Time: 75 minutes.
Airline: Air India, From: Bhubaneswar, To: Mumbai, Cost: 6000, Time: 150 minutes.
Total cost: 20000, Total time: 255 minutes
Flights to take:
Airline: Air India, From: Pune, To: Hyderabad, Cost: 10000, Time: 120 minutes.
Airline: Air India, From: Hyderabad, To: Bangalore, Cost: 3000, Time: 45 minutes.
Airline: Air India, From: Bangalore, To: Mumbai, Cost: 7000, Time: 90 minutes.
Total cost: 21000, Total time: 390 minutes
Flights to take:
Airline: Spice Jet, From: Pune, To: Hyderabad, Cost: 5000, Time: 120 minutes.
Airline: Air India, From: Hyderabad, To: Bangalore, Cost: 3000, Time: 45 minutes.
Airline: Spice Jet, From: Bangalore, To: Bhubaneswar, Cost: 7000, Time: 75 minutes.
Airline: Air India, From: Bhubaneswar, To: Mumbai, Cost: 6000, Time: 150 minutes.
Total cost: 21000, Total time: 390 minutes
Flights to take:
Airline: Air India, From: Pune, To: Hyderabad, Cost: 5000, Time: 120 minutes.
Airline: Air India, From: Hyderabad, To: Bangalore, Cost: 3000, Time: 45 minutes.
Airline: Spice Jet, From: Bangalore, To: Bhubaneswar, Cost: 7000, Time: 75 minutes.
Airline: Air India, From: Bhubaneswar, To: Mumbai, Cost: 6000, Time: 150 minutes.
Total cost: 26000, Total time: 495 minutes
Flights to take:
Airline: Spice Jet, From: Pune, To: Hyderabad, Cost: 5000, Time: 120 minutes.
Airline: Indigo, From: Hyderabad, To: Chennai, Cost: 2000, Time: 45 minutes.
Airline: Air India, From: Chennai, To: Kolkata, Cost: 6000, Time: 120 minutes.
Airline: Air India, From: Kolkata, To: Bangalore, Cost: 6000, Time: 120 minutes.
Airline: Air India, From: Bangalore, To: Mumbai, Cost: 7000, Time: 90 minutes.
Total cost: 26000, Total time: 495 minutes
Flights to take:
Airline: Air India, From: Pune, To: Hyderabad, Cost: 5000, Time: 120 minutes.
Airline: Indigo, From: Hyderabad, To: Chennai, Cost: 2000, Time: 45 minutes.
Airline: Air India, From: Chennai, To: Kolkata, Cost: 6000, Time: 120 minutes.
Airline: Air India, From: Kolkata, To: Bangalore, Cost: 6000, Time: 120 minutes.
Airline: Air India, From: Bangalore, To: Mumbai, Cost: 7000, Time: 90 minutes.
Total cost: 26000, Total time: 390 minutes
Flights to take:
Airline: Air India, From: Pune, To: Hyderabad, Cost: 10000, Time: 120 minutes.
Airline: Air India, From: Hyderabad, To: Bangalore, Cost: 3000, Time: 45 minutes.
Airline: Spice Jet, From: Bangalore, To: Bhubaneswar, Cost: 7000, Time: 75 minutes.
Airline: Air India, From: Bhubaneswar, To: Mumbai, Cost: 6000, Time: 150 minutes.
Total cost: 31000, Total time: 495 minutes
Flights to take:
Airline: Air India, From: Pune, To: Hyderabad, Cost: 10000, Time: 120 minutes.
Airline: Indigo, From: Hyderabad, To: Chennai, Cost: 2000, Time: 45 minutes.
Airline: Air India, From: Chennai, To: Kolkata, Cost: 6000, Time: 120 minutes.
Airline: Air India, From: Kolkata, To: Bangalore, Cost: 6000, Time: 120 minutes.
Airline: Air India, From: Bangalore, To: Mumbai, Cost: 7000, Time: 90 minutes.
Total cost: 32000, Total time: 630 minutes
Flights to take:
Airline: Spice Jet, From: Pune, To: Hyderabad, Cost: 5000, Time: 120 minutes.
Airline: Indigo, From: Hyderabad, To: Chennai, Cost: 2000, Time: 45 minutes.
Airline: Air India, From: Chennai, To: Kolkata, Cost: 6000, Time: 120 minutes.
Airline: Air India, From: Kolkata, To: Bangalore, Cost: 6000, Time: 120 minutes.
Airline: Spice Jet, From: Bangalore, To: Bhubaneswar, Cost: 7000, Time: 75 minutes.
Airline: Air India, From: Bhubaneswar, To: Mumbai, Cost: 6000, Time: 150 minutes.
Total cost: 32000, Total time: 630 minutes
Flights to take:
Airline: Air India, From: Pune, To: Hyderabad, Cost: 5000, Time: 120 minutes.
Airline: Indigo, From: Hyderabad, To: Chennai, Cost: 2000, Time: 45 minutes.
Airline: Air India, From: Chennai, To: Kolkata, Cost: 6000, Time: 120 minutes.
Airline: Air India, From: Kolkata, To: Bangalore, Cost: 6000, Time: 120 minutes.
Airline: Spice Jet, From: Bangalore, To: Bhubaneswar, Cost: 7000, Time: 75 minutes.
Airline: Air India, From: Bhubaneswar, To: Mumbai, Cost: 6000, Time: 150 minutes.
Total cost: 37000, Total time: 630 minutes
Flights to take:
Airline: Air India, From: Pune, To: Hyderabad, Cost: 10000, Time: 120 minutes.
Airline: Indigo, From: Hyderabad, To: Chennai, Cost: 2000, Time: 45 minutes.
Airline: Air India, From: Chennai, To: Kolkata, Cost: 6000, Time: 120 minutes.
Airline: Air India, From: Kolkata, To: Bangalore, Cost: 6000, Time: 120 minutes.
Airline: Spice Jet, From: Bangalore, To: Bhubaneswar, Cost: 7000, Time: 75 minutes.
Airline: Air India, From: Bhubaneswar, To: Mumbai, Cost: 6000, Time: 150 minutes.
Do you want to proceed to booking now? Enter Y for yes or N for no
N
Returning to main menu.
User Menu:
1. Minimum cost
2. All possible routes sorted by cost
3. Minimum time
4. All possible routes sorted by time
5. Flights with/without layovers
6. Return to main menu
3
Enter source city:
Pune
Enter destination city:
Kolkata
Minimum time to Kolkata is 285 minutes with cost 13000
Flights to take:
Airline: Spice Jet, From: Pune, To: Hyderabad, Cost: 5000, Time: 120 minutes.
Airline: Indigo, From: Hyderabad, To: Chennai, Cost: 2000, Time: 45 minutes.
Airline: Air India, From: Chennai, To: Kolkata, Cost: 6000, Time: 120 minutes.
Do you want to proceed to booking now? Enter Y for yes or N for no
N
Returning to main menu.
User Menu:
1. Minimum cost
2. All possible routes sorted by cost
3. Minimum time
4. All possible routes sorted by time
5. Flights with/without layovers
6. Return to main menu
4
Enter source city:
Pune
Enter destination city:
Kolkata
All possible routes from Pune to Kolkata sorted by time:
Total time: 285 minutes, Total cost: 13000
Flights to take:
Airline: Spice Jet, From: Pune, To: Hyderabad, Cost: 5000, Time: 120 minutes.
Airline: Indigo, From: Hyderabad, To: Chennai, Cost: 2000, Time: 45 minutes.
Airline: Air India, From: Chennai, To: Kolkata, Cost: 6000, Time: 120 minutes.
Total time: 285 minutes, Total cost: 18000
Flights to take:
Airline: Air India, From: Pune, To: Bangalore, Cost: 6000, Time: 120 minutes.
Airline: Spice Jet, From: Bangalore, To: Bhubaneswar, Cost: 7000, Time: 75 minutes.
Airline: Indigo, From: Bhubaneswar, To: Kolkata, Cost: 5000, Time: 90 minutes.
Total time: 285 minutes, Total cost: 13000
Flights to take:
Airline: Air India, From: Pune, To: Hyderabad, Cost: 5000, Time: 120 minutes.
Airline: Indigo, From: Hyderabad, To: Chennai, Cost: 2000, Time: 45 minutes.
Airline: Air India, From: Chennai, To: Kolkata, Cost: 6000, Time: 120 minutes.
Total time: 285 minutes, Total cost: 15000
Flights to take:
Airline: Spice Jet, From: Pune, To: Bangalore, Cost: 3000, Time: 120 minutes.
Airline: Spice Jet, From: Bangalore, To: Bhubaneswar, Cost: 7000, Time: 75 minutes.
Airline: Indigo, From: Bhubaneswar, To: Kolkata, Cost: 5000, Time: 90 minutes.
Total time: 285 minutes, Total cost: 18000
Flights to take:
Airline: Air India, From: Pune, To: Hyderabad, Cost: 10000, Time: 120 minutes.
Airline: Indigo, From: Hyderabad, To: Chennai, Cost: 2000, Time: 45 minutes.
Airline: Air India, From: Chennai, To: Kolkata, Cost: 6000, Time: 120 minutes.
Total time: 330 minutes, Total cost: 20000
Flights to take:
Airline: Spice Jet, From: Pune, To: Hyderabad, Cost: 5000, Time: 120 minutes.
Airline: Air India, From: Hyderabad, To: Bangalore, Cost: 3000, Time: 45 minutes.
Airline: Spice Jet, From: Bangalore, To: Bhubaneswar, Cost: 7000, Time: 75 minutes.
Airline: Indigo, From: Bhubaneswar, To: Kolkata, Cost: 5000, Time: 90 minutes.
Total time: 330 minutes, Total cost: 20000
Flights to take:
Airline: Air India, From: Pune, To: Hyderabad, Cost: 5000, Time: 120 minutes.
Airline: Air India, From: Hyderabad, To: Bangalore, Cost: 3000, Time: 45 minutes.
Airline: Spice Jet, From: Bangalore, To: Bhubaneswar, Cost: 7000, Time: 75 minutes.
Airline: Indigo, From: Bhubaneswar, To: Kolkata, Cost: 5000, Time: 90 minutes.
Total time: 330 minutes, Total cost: 25000
Flights to take:
Airline: Air India, From: Pune, To: Hyderabad, Cost: 10000, Time: 120 minutes.
Airline: Air India, From: Hyderabad, To: Bangalore, Cost: 3000, Time: 45 minutes.
Airline: Spice Jet, From: Bangalore, To: Bhubaneswar, Cost: 7000, Time: 75 minutes.
Airline: Indigo, From: Bhubaneswar, To: Kolkata, Cost: 5000, Time: 90 minutes.
Total time: 425 minutes, Total cost: 19000
Flights to take:
Airline: Indigo, From: Pune, To: Mumbai, Cost: 2000, Time: 20 minutes.
Airline: Air India, From: Mumbai, To: Bhopal, Cost: 4000, Time: 120 minutes.
Airline: Spice Jet, From: Bhopal, To: Hyderabad, Cost: 5000, Time: 120 minutes.
Airline: Indigo, From: Hyderabad, To: Chennai, Cost: 2000, Time: 45 minutes.
Airline: Air India, From: Chennai, To: Kolkata, Cost: 6000, Time: 120 minutes.
Total time: 425 minutes, Total cost: 18000
Flights to take:
Airline: Indigo, From: Pune, To: Mumbai, Cost: 2000, Time: 20 minutes.
Airline: Indigo, From: Mumbai, To: Bhopal, Cost: 3000, Time: 120 minutes.
Airline: Spice Jet, From: Bhopal, To: Hyderabad, Cost: 5000, Time: 120 minutes.
Airline: Indigo, From: Hyderabad, To: Chennai, Cost: 2000, Time: 45 minutes.
Airline: Air India, From: Chennai, To: Kolkata, Cost: 6000, Time: 120 minutes.
Total time: 470 minutes, Total cost: 26000
Flights to take:
Airline: Indigo, From: Pune, To: Mumbai, Cost: 2000, Time: 20 minutes.
Airline: Air India, From: Mumbai, To: Bhopal, Cost: 4000, Time: 120 minutes.
Airline: Spice Jet, From: Bhopal, To: Hyderabad, Cost: 5000, Time: 120 minutes.
Airline: Air India, From: Hyderabad, To: Bangalore, Cost: 3000, Time: 45 minutes.
Airline: Spice Jet, From: Bangalore, To: Bhubaneswar, Cost: 7000, Time: 75 minutes.
Airline: Indigo, From: Bhubaneswar, To: Kolkata, Cost: 5000, Time: 90 minutes.
Total time: 470 minutes, Total cost: 25000
Flights to take:
Airline: Indigo, From: Pune, To: Mumbai, Cost: 2000, Time: 20 minutes.
Airline: Indigo, From: Mumbai, To: Bhopal, Cost: 3000, Time: 120 minutes.
Airline: Spice Jet, From: Bhopal, To: Hyderabad, Cost: 5000, Time: 120 minutes.