-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAeroplaneSeatReservation.java
281 lines (233 loc) · 8.28 KB
/
AeroplaneSeatReservation.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
import java.util.Scanner;
public class AeroplaneSeatReservation
{
int counter = 0 ;
double cost = 0.0 ;
String name = "" ;
String date = "" ;
String currentLocation = "" ;
String destination = "" ;
String phoneNumber = "" ;
String[] reservedSeat = new String[50];
String[] reservedSeat2 = {"1A","2F","3A","3B","3F","4A","5E","5F","6A","6B","6C","7B","7C","7D","7E","8A","8F","9A","9B","10D","10E","10F","11A","11B","11C","11D","11E","11F"};
int k = 27;
void accept(Scanner sc)
{
// accepting name
String s1 = "Your name please!";
for(int i = 0 ;i < s1.length() ; i++)
{
char ch = s1.charAt(i);
System.out.print(ch);
try
{
Thread.sleep(55);
}
catch(Exception e)
{
}
}
System.out.println();
name = sc.nextLine().trim() ;
// capitalizing name
String name2 = this.name ;
name2 = name2 + " " ;
String word = "" ;
String newWord = "";
String s2 = "";
for(int i = 0 ; i < name2.length() ; i++)
{
char ch = name2.charAt(i);
word = word + ch ;
if(ch == ' ')
{
char firstWord = word.charAt(0);
newWord = word.substring(1);
firstWord = Character.toUpperCase(firstWord);
newWord = firstWord + newWord ;
s2 = s2 + newWord ;
word = "" ;
}
}
name = s2 ;
this.name = name2;
// accpeting phone number
s1 = "Please enter your phone number";
for(int i = 0 ;i < s1.length() ; i++)
{
char ch = s1.charAt(i);
System.out.print(ch);
try
{
Thread.sleep(55);
}
catch(Exception e)
{
}
}
System.out.println();
phoneNumber = sc.nextLine().trim() ;
// phone number check
if( phoneNumber.length() != 10)
{
boolean flag = false;
while(flag == false)
{
System.out.println("Please make sure that the phone number that you have entered is 10 digits long \nThe phone number entered by you was " + phoneNumber.length() + " digits long");
phoneNumber = sc.nextLine().trim();
if(phoneNumber.length() == 10)
{
flag = true;
}
}
}
// accepting date of travel
s1 = "Please enter your date of travel";
for(int i = 0 ;i < s1.length() ; i++)
{
char ch = s1.charAt(i);
System.out.print(ch);
try
{
Thread.sleep(55);
}
catch(Exception e)
{
}
}
System.out.println();
date = sc.nextLine().trim() ;
// accepting current location and destination of travel
s1 = "Please enter your current location and destination";
for(int i = 0 ;i < s1.length() ; i++)
{
char ch = s1.charAt(i);
System.out.print(ch);
try
{
Thread.sleep(55);
}
catch(Exception e)
{
}
}
System.out.println();
currentLocation = sc.nextLine().trim() ;
destination = sc.nextLine().trim();
currentLocation = currentLocation.toUpperCase();
destination = destination.toUpperCase();
}
void displayAirplaneSeats()
{
//display statement
System.out.println(" Business class: ");
System.out.println("▢ 1A 1F ▢");
System.out.println("▢ 2A 2F ▢");
System.out.println(" First Class ");
System.out.println("▢ 3A 3B 3E 3F ▢");
System.out.println("▢ 4A 4B 4E 4F ▢");
System.out.println("▢ 5A 5B 5E 5F ▢");
System.out.println(" Economy Class ");
System.out.println("▢ 6A 6B 6C 6D 6E 6F ▢");
System.out.println("▢ 7A 7B 7C 7D 7E 7F ▢");
System.out.println("▢ 8A 8B 8C 8D 8E 8F ▢");
System.out.println("▢ 9A 9B 9C 9D 9E 9F ▢");
System.out.println("▢ 10A 10B 10C 10D 10E 10F ▢");
System.out.println("▢ 11A 11B 11C 11D 11E 11F ▢");
//displaying the reserved seats
System.err.println("The reserved seats are: ");
for(int i = 0 ; i <= k ; i++)
{
System.err.println(reservedSeat2[i]);
reservedSeat[i] = reservedSeat2[i];
}
System.err.println();
System.err.println("PLEASE SCROLL UP TO SEE ALL THE RESERVED SEATS");
}
void Choose()
{
Scanner input = new Scanner(System.in);
//InputDetails obj1 = new InputDetails();
boolean check = true;
boolean flag = false;
while(check == true && k < 50)
{
//display statement
System.out.println("Please enter the seat number that you want to reserve ");
String seat = input.nextLine().trim();
int numSeat = Integer.parseInt(seat.substring(0,1));
for(int i = 0 ; i <= k ; i++)
{
if(reservedSeat[i].equals(seat))
{
System.out.println("OOPS LOOKS LIKE YOU THAT SEAT HAS ALREADY BEEN RESERVED!!");
flag = true;
}
}
if(flag == false)
{
k++;
reservedSeat[k] = seat;
}
System.out.println("do you want to reserve another seat ?");
if( input.nextLine().trim().equalsIgnoreCase("yes"))
{
if(flag == false)
{
System.out.println("Boarding Pass: ") ;
System.out.println();
System.out.println(name + "\t" + "Flight: OKL012" + "\t" + "seat number: " + reservedSeat[k]);
System.out.println("Gate: 47 date: " + date);
System.out.println("from " + currentLocation + " to " + destination);
System.out.println("\n" + "Have a great time" );
if(numSeat == 1 || numSeat == 2)
{
cost = cost + 200000;
}
else if ( numSeat == 3 || numSeat == 4 || numSeat == 5)
{
cost = cost + 110000;
}
else
{
cost = cost = 60000;
}
}
check = true;
flag = false;
}
else
{
System.out.println("Boarding Pass: ") ;
System.out.println();
System.out.println(name + "\t" + "Flight: OKL012" + "\t" + "seat number: " + reservedSeat[k]);
System.out.println("Gate: 47 date: " + date);
System.out.println("from " + currentLocation + " to " + destination);
System.out.println("\n" + "Have a great time" );
if(numSeat == 1 || numSeat == 2)
{
cost = cost + 200000;
}
else if ( numSeat == 3 || numSeat == 4 || numSeat == 5)
{
cost = cost + 110000;
}
else
{
cost = cost = 60000;
}
check = false;
flag = false;
}
flag = false;
}
}
public static void main(String args[])
{
AeroplaneSeatReservation obj = new AeroplaneSeatReservation();
Scanner sc = new Scanner(System.in);
obj.accept(sc);
obj.displayAirplaneSeats();
obj.Choose();
}
}