-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAirlineReservationSystem.java
More file actions
188 lines (170 loc) · 7 KB
/
Copy pathAirlineReservationSystem.java
File metadata and controls
188 lines (170 loc) · 7 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
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
package com.mycompany.airlinereservation;
import java.util.Scanner;
public class AirlineReservation {
private static boolean[] seats = new boolean[100];
private static boolean isFlightDelayed = false;
private static int destinationTemperature;
private static String selectedDestination;
// Adding user details
private static final String[] USERS = {"Srivatsan", "Tanish", "Shaifali"};
private static final String[] PASSWORDS = {"Srivatsan", "Tanish", "Shaifali"};
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
while (true) {
String username = login(input);
if (username != null) {
System.out.println("Login Successful! Welcome, " + username + "!");
System.out.println("Most Popular Places to Travel are ");
viewPopularPlaces();
System.out.print("Enter the number of your desired destination: ");
int destinationChoice = input.nextInt();
selectedDestination = getDestinationName(destinationChoice);
System.out.println("You selected: " + selectedDestination);
while (true) {
System.out.println("1. Reserve a seat for " + selectedDestination);
System.out.println("2. View all seats for " + selectedDestination);
System.out.println("3. Check Flight Status for " + selectedDestination);
System.out.println("4. Check Destination Temperature for " + selectedDestination);
System.out.println("5. Check Destination Airport for " + selectedDestination);
System.out.println("6. Change Destination");
System.out.println("7. Logout");
int choice = input.nextInt();
switch (choice) {
case 1:
reserveSeat(selectedDestination);
break;
case 2:
viewSeats(selectedDestination);
break;
case 3:
checkFlightStatus(selectedDestination);
break;
case 4:
checkDestinationTemperature(selectedDestination);
break;
case 5:
checkDestinationAirport(selectedDestination);
break;
case 6:
selectedDestination = null;
break;
case 7:
System.out.println("Logged out successfully.");
break;
default:
System.out.println("Invalid choice. Please try again.");
}
if (choice == 7 || selectedDestination == null) {
break;
}
}
} else {
System.out.println("Invalid username or password. Please try again.");
}
}
}
private static String login(Scanner input) {
System.out.print("Enter username: ");
String username = input.next();
System.out.print("Enter password: ");
String password = input.next();
for (int i = 0; i < USERS.length; i++) {
if (username.equalsIgnoreCase(USERS[i]) && password.equals(PASSWORDS[i])) {
return USERS[i];
}
}
return null;
}
private static void viewPopularPlaces() {
System.out.println("Popular Places to Travel:");
System.out.println("1. Paris");
System.out.println("2. New York City");
System.out.println("3. Tokyo");
System.out.println("4. London");
}
private static String getDestinationName(int choice) {
switch (choice) {
case 1:
return "Paris";
case 2:
return "New York City";
case 3:
return "Tokyo";
case 4:
return "London";
default:
return null;
}
}
private static void reserveSeat(String destination) {
Scanner input = new Scanner(System.in);
System.out.print("Enter seat number for " + destination + ": ");
int seatNum = input.nextInt();
if (seatNum >= 1 && seatNum <= 100) {
if (!seats[seatNum - 1]) {
seats[seatNum - 1] = true;
System.out.println("Your seat for " + destination + " has been reserved. Thank you.");
} else {
System.out.println("Sorry, this seat for " + destination + " is already reserved.");
}
} else {
System.out.println("Invalid seat number.");
}
}
private static void viewSeats(String destination) {
System.out.println("Seats for " + destination + ":");
for (int i = 0; i < seats.length; i++) {
int seatNumber = i + 1;
System.out.print("Seat " + seatNumber + ": ");
if (seats[i]) {
System.out.println("Reserved");
} else {
System.out.println("Available");
}
}
}
private static void checkFlightStatus(String destination) {
if (isFlightDelayed) {
System.out.println("The flight to " + destination + " is delayed.");
} else {
System.out.println("The flight to " + destination + " is on time.");
}
}
private static void checkDestinationTemperature(String destination) {
int temperature;
switch (destination) {
case "Paris":
temperature = 13;
break;
case "New York City":
temperature = 8;
break;
case "Tokyo":
temperature = 21;
break;
case "London":
temperature = 11;
break;
default:
temperature = 0;
break;
}
System.out.println("The temperature at " + destination + " is " + temperature + "°C.");
}
private static void checkDestinationAirport(String destination) {
String airport;
switch (destination) {
case "Paris":
System.out.println(" The Airport of Paris is called Paris Charles de Gaulle Airport");
break;
case "New York City":
System.out.println("The Airport of New York City is called John F. Kennedy International Airport");
break;
case "Tokyo":
System.out.println("The Airport Of Tokyo is Called Haneda Airport");
break;
case "London":
System.out.println("The Airport Of London is called London International Airport");
}
}
}