-
Notifications
You must be signed in to change notification settings - Fork 0
/
RailwayReservation.java
378 lines (313 loc) · 12.8 KB
/
RailwayReservation.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
package RailwayReservation;
import java.io.*;
public class RailwayReservation {
public static void main(String args[]) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String user,password,yn,search,again,choice;
int to=0,y=1,z=0,end=0,r=1;
int available[] = new int[6];
int ticketI[][] = new int [100][3];
String ticketS[][] = new String[100][3];
double ticketD[][] = new double [100][3];
double pay[] = new double[20];
double change[] = new double[20];
for(int i=1;i<4;){
System.out.print("Enter Username: ");
user = in.readLine();
System.out.print("Enter Password: ");
password = in.readLine();
//"available[]" is the SEAT AVAILABLE//
//store 20 seats every destination [1-5]//
for(int o=1; o<=5; o++){
available[o]=20;
}
//if user and password are correct proceed to MAIN MENU//
if(user.equals("1") && password.equals("1")){
for(int x=1; x==1;){
//the MAIN MENU//
System.out.println("******");
System.out.println("* RAILWAY RESERVATION AND TICKETING SYSTEM *");
System.out.println("******");
System.out.println("* [1] Destination *");
System.out.println("* [2] Passengers *");
System.out.println("* [3] Billing *");
System.out.println("* [4] View *");
System.out.println("* [5] Exit *");
System.out.println("*****");
System.out.println("*****\n");
for(x=1; x==1;){
System.out.print("ENTER CHOICE: ");
choice=in.readLine();
//if CHOICE is "1" display the DESTINATION//
if (choice.equals("1")){
//the DESTINATION DETAILS//
//display the "Destination", every destination "Fare", and the "Seat" available//
System.out.println("*****");
System.out.println("* DESTINATION | FARE | SEAT *");
System.out.println("*****");
System.out.println("* 1.)AMBALA STATION | 250 | "+available[1]+" *");
System.out.println("* 2.)DELHI STATION | 400 | "+available[2]+" *");
System.out.println("* 3.)AMRITSAR STATION | 300 | "+available[3]+" *");
System.out.println("* 4.)JALANDHAR STATION | 250 | "+available[4]+" *");
System.out.println("* 5.)CHANDIGARH STATION |200 | "+available[5]+" *");
System.out.println("*****");
System.out.println("*****\n");
System.out.println("PWD, STUDENT, & SENIOR CITIZEN with 20% DISCOUNT!!!\n");
x=0;
}
//if CHOICE is "2" proceed to Ticket Booking//
else if (choice.equals("2")){
int print=1;
//display first the Destination Details//
System.out.println("*****");
System.out.println("* DESTINATION | FARE | SEAT *");
System.out.println("*****");
System.out.println("* 1.)AMBALA STATION | 250 | "+available[1]+" *");
System.out.println("* 2.)DELHI STATION | 400 | "+available[2]+" *");
System.out.println("* 3.)AMRITSAR STATION |300 | "+available[3]+" *");
System.out.println("* 4.)JALANDHAR STATION | 250 | "+available[4]+" *");
System.out.println("* 5.)CHANDIGARH STATION | 200 | "+available[5]+" *");
System.out.println("*****");
System.out.println("*****\n");
System.out.println("PWD, STUDENT, & SENIOR CITIZEN with 20% DISCOUNT!!!\n");
if((available[1]==0)&&(available[2]==0)&&(available[3]==0)&&(available[4]==0)&&(available[5]==0)){
System.out.println("Sorry, We don't have available seats for all Destination!");
x=0;
}
//inputing of Passenger's Name//
else{
for(x=1; x==1;){
System.out.print("\nENTER PASSENGER'S NAME: ");
ticketS[z][0] = in.readLine();
x=0;
//if Passenger's Name already used, display error and go back to Inputing//
for(int l=0; l<z; l++){
if(ticketS[l][0].equalsIgnoreCase(ticketS[z][0])){
System.out.println("Sorry, Passenger's name have already used!");
x=1;
}
}
}
//inputing of Destination//
//integers Only [1-5]//
for(x=1; x==1;){
System.out.print("ENTER DESTINATION [number]: ");
to = Integer.parseInt(in.readLine());
//if Inputed integers are "<1" or ">5", display error and go back to Inputing//
if(to<1 || to>5){
System.out.println("Invalid Input!");
x=1;
}
//if available seat is eqaul to "Zero", display error and go back to Inputing//
for(int d=1; d<=5; d++){
if(to==d){
if(available[to]==0){
System.out.println("Sorry, We don't have available seat!");
x=1;
}
x=0;
}
}
}
//convert the integer to string//
String dest[] = { " ", "AMBALA STATION", "DELHI STATION", "AMRITSAR STATION", "JALANDHAR STATION", "CHANDIGARH STATION1"
+ ""};
double fare[] = { 0,600,170,150,200,250};
//converted integer to string, transfer to storage array//
ticketS[z][1] = dest[to];
ticketD[z][0] = fare[to];
//inputing for Number of Passenger's//
for(x=1; x==1;){
System.out.print("HOW MANY PASSENGERS ARE YOU?: ");
ticketI[z][0] = Integer.parseInt(in.readLine());
//subtract the available seat by the the number inputed//
for(int p=1; p<=5; p++){
if(to==p){
print=1;
available[to] = available[to]-ticketI[z][0];
//if the subtracted available seat is "<0", display error//
//add the inputed number to the subtracted seat, to back the original seat//
//display the available seat and back to the inputing//
if(available[to]<0){
System.out.print("Sorry, We don't have seat available for " +ticketI[z][0] +" person\n");
available[to] = available[to]+ticketI[z][0];
System.out.print("We only have " +available[to] +" seat available\n");
x=1;
print=0;
}
else{
x=0;
}
}
}
}
//inputing for Number of Discounted Passenger's//
for(x=1;x==1;){
System.out.print("HOW MANY PASSENGERS HAVE DISCOUNT?: ");
ticketI[z][1] = Integer.parseInt(in.readLine());
if(ticketI[z][1]>ticketI[z][0]){
System.out.println("Invalid Input!");
System.out.println("No. of Passengers are only " +ticketI[z][0] +"!");
x=1;
}
else{
break;
}
}
//print out of passengers details....
if(print==1){
System.out.println("\n*******");
System.out.println("* PASSENGER'S DETAILS *");
System.out.println("*****");
System.out.println("PASSENGER'S NAME: " + ticketS[z][0]);
System.out.println("PASSENGER'S DESTINATION : " + ticketS[z][1]);
System.out.println("FARE PRICE: Rs " + ticketD[z][0]);
System.out.println("NO. OF PASSENGERS: " + ticketI[z][0]);
System.out.println("NO. OF PASSENGERS WITH DISCOUNT: " + ticketI[z][1]);
System.out.println("*****");
System.out.println("*****\n");
ticketS[z][2]="0";
double discount=(ticketD[z][0]-(ticketD[z][0]*0.2))*ticketI[z][1];
ticketD[z][2]= ((ticketI[z][0]-ticketI[z][1])*ticketD[z][0])+discount;
x=0;
}
z++;
}
}
else if (choice.equals("3")){
for(x=1; x==1;){
System.out.print("ENTER PASSENGER'S NAME: ");
search = in.readLine();
int s=1;
for(int b=0;b<z;b++){
if(search.equalsIgnoreCase(ticketS[b][0])){
System.out.println("*****");
System.out.println("* PASSENGER'S DETAILS *");
System.out.println("*****");
System.out.println("PASSENGER'S NAME: " + ticketS[b][0]);
System.out.println("PASSENGER'S DESTINATION : " + ticketS[b][1]);
System.out.println("FARE PRICE: Rs" + ticketD[b][0]);
System.out.println("NO. OF PASSENGERS: " + ticketI[b][0]);
System.out.println("NO. OF PASSENGERS WITH DISCOUNT: " + ticketI[b][1]);
System.out.println("*****");
System.out.println("*****");
s=0;
x=0;
if(ticketS[b][2].equals("x")){
System.out.println("Passenger's Already Paid!");
x=0;
}
else{
ticketS[b][2]="x";
for(x=1; x==1;){
System.out.println("\nPASSENGER'S TOTAL FARE: Rs "+ticketD[b][2]);
System.out.print("ENTER AMOUNT TO PAY: ");
pay[b] = Double.parseDouble(in.readLine());
change[b]=pay[b]-ticketD[b][2];
if(change[b]<0){
System.out.println("Invalid Input!");
x=1;
}
else{
System.out.println("CHANGE: Rs "+change[b]);
System.out.println("");
x=0;
}
}
}
}
}
if (s==1){
System.out.println("\nPASSENGER'S NAME NOT FOUND!\n");
for(int q=1; q==1;){
System.out.print("Do you wish to continue with this transaction? [Y/N]: ");
again=in.readLine();
if(again.equalsIgnoreCase("y")){
q=0;
}
else if (again.equalsIgnoreCase("n")){
q=0;
x=0;
}
else{
System.out.println("\nInvalid input!\n");
}
}
}
}
}
else if (choice.equals("4")){
for(int sx=1; sx<=3;){
System.out.print("SEARCH PASSENGER'S NAME: ");
search = in.readLine();
int s=1;
for(x=0; x<=z; x++){
if(search.equalsIgnoreCase(ticketS[x][0])){
System.out.println("*****");
System.out.println("* PASSENGER'S DETAILS *");
System.out.println("*****");
System.out.println("PASSENGER'S NAME: " + ticketS[x][0]);
System.out.println("PASSENGER'S DESTINATION : " + ticketS[x][1]);
System.out.println("FARE PRICE: Rs" + ticketD[x][0]);
System.out.println("NO. OF PASSENGERS: " + ticketI[x][0]);
System.out.println("NO. OF PASSENGERS WITH DISCOUNT: " + ticketI[x][1]);
System.out.println("TOTAL FARE PRICE: Rs " + ticketD[x][2]);
if(ticketS[x][2].equals("x")){
System.out.println("PAY: Rs " +pay[x]);
System.out.println("CHANGE: Rs " +change[x]);
System.out.println("STATUS: PAID");
}
else{
System.out.println("STATUS: NOT PAID");
}
System.out.println("*****");
System.out.println("*****");
s=0;
sx=4;
}
}
if (s==1){
System.out.println("Passenger's Name not found!");
sx++;
}
}
}
else if(choice.equals("5")){
end=1;
x=0;
System.out.println("Thank You!");
}
else{
System.out.println("Invalid Input!");
x=1;
}
}
for(y=1; y==1;){
if(end==1){
break;
}
System.out.print("Do you want another transaction? [Y/N]: ");
yn = in.readLine();
if (yn.equalsIgnoreCase("y")){
x=1;
y=0;
}
else if (yn.equalsIgnoreCase("n")){
System.out.println("\nThank You!!!");
break;
}
else{
System.out.println("Invalid Input!!!");
y=1;
}
}
}
i=4;
}
else{
System.out.println("\nInvalid user or password!\n");
i++;
}
}
}
}