-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest_RailwaySystem.java
More file actions
469 lines (445 loc) · 18 KB
/
Copy pathTest_RailwaySystem.java
File metadata and controls
469 lines (445 loc) · 18 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
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
package railway_system;
import java.util.*;
public class Test_RailwaySystem extends User_Details{
int accept_login()//asks user for which type of login does he want to opt for
{
System.out.println("Choose from following numbers to access corresponding login: ");
System.out.println();
System.out.println("1.Administration Login");
System.out.println("2.User Login");
System.out.println("3.Agent Login");
System.out.println("4.Exit");
System.out.println();
Scanner sc=new Scanner(System.in);
System.out.print("Enter your choice:");
int accept=sc.nextInt();
if(accept>0 && accept<=4)
{
return accept;
}
return accept_login();
}
int accept_administrator_choice()//asks administrator to enter which operation he/she wants to performs
{
System.out.println("Choose from following numbers to perform corresponding operation: ");
System.out.println();
System.out.println("1.Add coach to a train");
System.out.println("2.Delete coach from a train");
System.out.println("3.Add a new train to railway system");
System.out.println("4.Delete a train from railway system");
System.out.println("5.Exit");
System.out.println();
Scanner sc=new Scanner(System.in);
System.out.print("Enter your choice:");
int accept=sc.nextInt();
if(accept>0 && accept<=5)
{
return accept;
}
return accept_administrator_choice();
}
int accept_payment_choice()//asks for payment method
{
System.out.println("Choose from following payment options and enter corresponding number: ");
System.out.println();
System.out.println("1.Debit/Credit Cards.");
System.out.println("2.UPI ID.");
Scanner sc=new Scanner(System.in);
System.out.print("Enter your choice:");
int accept=sc.nextInt();
if(accept>0 && accept<=2)
{
return accept;
}
return accept_payment_choice();
}
void payment(double ticket_fare)
{
Test_RailwaySystem trs_obj=new Test_RailwaySystem();//object of Test_RailwaySystem
Payment_Details p_obj=new Payment_Details();
int choice=trs_obj.accept_payment_choice();
System.out.println();
switch(choice)
{
case 1:p_obj.card_payment(ticket_fare);
break;
case 2:p_obj.upi_id(ticket_fare);
break;
}
}
void administration()//all operations to be performed by administrator
{
Test_RailwaySystem trs_obj=new Test_RailwaySystem();//object of Test_RailwaySystem
User_Details u_obj=new User_Details();//object of User_Details
Train_details t_obj=new Train_details();//object of Train_details
Administration_Login adm_obj=new Administration_Login();//object of Administration_Login
Agent_Login a_login=new Agent_Login();//object of Agent_Login
Payment_Details p_obj=new Payment_Details();
Train_details[] arr=t_obj.forward_journey();//original list of trains
Scanner sc=new Scanner(System.in);
u_obj.get_captcha();
System.out.println();
System.out.println("You have access to Administration Login");
System.out.println();
int choice=trs_obj.accept_administrator_choice();
switch(choice)//switch loop based on operations performed by administrator
{
case 1:System.out.println("You want to add coach to a train");//adding a coach
System.out.println();
System.out.println("Following is list of trains:");//displaying trains before addition of coach
for(int i=0;i<arr.length-1;i++)
{
System.out.print(arr[i].head.PNR_NO + "\t");
t_obj.show(arr[i].head);
System.out.println();
}
System.out.println();
System.out.print("Enter Train Number into which you want to add the coach:");
long add_coach=sc.nextLong();
System.out.println();
u_obj.make_bst(arr, add_coach);
int otp=p_obj.get_otp();
System.out.println("OTP : " + otp);
System.out.print("Enter above OTP to proceed: ");
int get_otp=sc.nextInt();
System.out.println();
if(!p_obj.check_otp(otp,get_otp))
{
System.out.println("Sorry! You entered incorrect OTP.");
System.out.println("Coach could not be added.");
System.out.println("-----Exit-----");
System.exit(0);
}
System.out.println("Original number of seats in Train Number " + add_coach + " is " + arr[0].head.no_of_seats);
System.out.println();
adm_obj.add_coach(add_coach);
System.out.println();
System.out.println("Congratulations! New coach has been added successfully.");
break;//end of addition of coach
case 2:System.out.println("You want to delete coach from a train");//deleting a coach
System.out.println();
System.out.println("Following is list of trains:");//displaying trains before deletion of coach
for(int i=0;i<arr.length-1;i++)
{
System.out.print(arr[i].head.PNR_NO + "\t");
t_obj.show(arr[i].head);
System.out.println();
}
System.out.println();
System.out.print("Enter Train Number from which you want to delete the coach:");
long del_coach=sc.nextLong();
System.out.println();
u_obj.make_bst(arr, del_coach);
int otp1=p_obj.get_otp();
System.out.println("OTP : " + otp1);
System.out.print("Enter above OTP to proceed: ");
int get_otp1=sc.nextInt();
System.out.println();
if(!p_obj.check_otp(otp1,get_otp1))
{
System.out.println("Sorry! You entered incorrect OTP.");
System.out.println("Coach could not be deleted.");
System.out.println("-----Exit-----");
System.exit(0);
}
System.out.println("Original number of seats in Train Number " + del_coach + " is " + arr[0].head.no_of_seats);
adm_obj.delete_coach(del_coach);
System.out.println();
System.out.println("Congratulations! Coach has been deleted successfully.");
break;//end of deletion of coach
case 3:System.out.println("You want to add a new train to railway system");//adding a new train
int otp2=p_obj.get_otp();
System.out.println("OTP : " + otp2);
System.out.print("Enter above OTP to proceed: ");
int get_otp2=sc.nextInt();
System.out.println();
if(!p_obj.check_otp(otp2,get_otp2))
{
System.out.println("Sorry! You entered incorrect OTP.");
System.out.println("New Train could not be added.");
System.out.println("-----Exit-----");
System.exit(0);
}
System.out.println("Enter the following details of new train.");
System.out.println();
System.out.print("Enter the total number of stations where train will have halts in its entire journey:");
int station=sc.nextInt();
System.out.println();
Node newtrain=adm_obj.new_train(station);
System.out.println();
System.out.println("Details of new train are as follows: ");
System.out.println();
t_obj.show_train_details(newtrain);
System.out.println();
System.out.println("Following is updated list of trains after addition of new train:");
System.out.print(newtrain.PNR_NO + "\t");
t_obj.show(newtrain);//printing new train
System.out.println();
for(int i=0;i<arr.length-1;i++)//printing already existing trains
{
System.out.print(arr[i].head.PNR_NO + "\t");
t_obj.show(arr[i].head);
System.out.println();
}
System.out.println();
System.out.println("Congratulations! New train has been added successfully.");
System.out.println();
System.out.println();
break;//end of addition of new train
case 4:System.out.println("You want to delete a train from railway system");//deleting a train
System.out.println();
System.out.println("Following is list of trains:");//displaying trains before deletion
System.out.println();
for(int i=0;i<arr.length-1;i++)
{
System.out.print(arr[i].head.PNR_NO + "\t");
t_obj.show(arr[i].head);
System.out.println();
}
System.out.println();
System.out.print("Enter Train Number of the train that u want to delete:");
long del_train=sc.nextLong();
System.out.println();
u_obj.make_bst(arr, del_train);
int otp3=p_obj.get_otp();
System.out.println("OTP : " + otp3);
System.out.print("Enter above OTP to proceed: ");
int get_otp3=sc.nextInt();
System.out.println();
if(!p_obj.check_otp(otp3,get_otp3))
{
System.out.println("Sorry! You entered incorrect OTP.");
System.out.println("Train could not be added.");
System.out.println("-----Exit-----");
System.exit(0);
}
System.out.println();
Train_details[] arr1=adm_obj.delete_train(del_train);
System.out.println("Following is updated list of trains after deletion:");//displaying trains after deletion
for(int i=0;i<arr1.length-1;i++)
{
System.out.print(arr[i].head.PNR_NO + "\t");
t_obj.show(arr1[i].head);
System.out.println();
}
System.out.println();
System.out.println("Congratulations! Train has been deleted successfully.");
break;//end of deletion of train
case 5:System.out.println("You have chosen to exit");//choosen to exit
System.out.println("Thank you......");
System.exit(0);
break;//end of exit
}
}
void user() //access to user login
{
Test_RailwaySystem trs_obj=new Test_RailwaySystem();//object of Test_RailwaySystem
User_Details u_obj=new User_Details();//object of User_Details
Train_details t_obj=new Train_details();//object of Train_details
Administration_Login adm_obj=new Administration_Login();//object of Administration_Login
Agent_Login a_login=new Agent_Login();//object of Agent_Login
Payment_Details p_obj=new Payment_Details();
Train_details[] arr=t_obj.forward_journey();//original list of trains
Scanner sc=new Scanner(System.in);
System.out.println();
u_obj.get_captcha();
System.out.println();
System.out.println("You have access to User Login");
System.out.println();
System.out.println("Following is list of trains:");//displaying list of trains
for(int i=0;i<arr.length-1;i++)
{
System.out.print(arr[i].head.PNR_NO + "\t");
t_obj.show(arr[i].head);
System.out.println();
}
System.out.println();
System.out.print("Enter from where you want to board the train: ");
String source=sc.nextLine();
System.out.print("Enter your destination: ");
String destination=sc.nextLine();
System.out.println();
System.out.println("Available trains are: ");
ArrayList<Train_details> valid_arr=u_obj.check_source_destination(source, destination);
u_obj.valid_trains(valid_arr);
System.out.println();
System.out.print("Enter Train Number in which you want to travel: ");
long book_train=sc.nextLong();
u_obj.make_bst(valid_arr, book_train);
int j=u_obj.valid_train_index(valid_arr, book_train);
System.out.println();
System.out.println("You have chosen the following train: ");
System.out.print(valid_arr.get(j).head.PNR_NO + "\t");
u_obj.show(valid_arr.get(j).head);
System.out.println();
System.out.println();
int no_of_tickets=u_obj.no_of_tickets();
System.out.println();
User_Details[] user_arr=u_obj.user_details(no_of_tickets);
System.out.println();
System.out.println("Following are passenger details entered and their corresponding ticket fares.");
System.out.println("Full Name " + "\t" +"Gender" + "\t" + "Age" + "\t" + "Quota" + "\t" + "Coach" + "\t" + "Fare");
double total_fare=0;
for(int i=0;i<user_arr.length;i++)
{
user_arr[i].user_head.gender=u_obj.gender(user_arr[i].user_head.gender);
user_arr[i].user_head.quota=u_obj.quota(user_arr[i].user_head.quota);
user_arr[i].user_head.coach_type=u_obj.coach_type(user_arr[i].user_head.coach_type);
double fare=u_obj.ticket_fare(user_arr[i].user_head,u_obj.ticket_fare(valid_arr.get(j).head, source, destination, user_arr[i].user_head.quota));
u_obj.show(user_arr[i].user_head);
System.out.print(fare);
System.out.println();
total_fare+=fare;
}
total_fare=Math.round(total_fare*100)/100.0;//rounding off total fare to two decimal places
System.out.println();
System.out.println("Total fare to be paid is : " + total_fare);
System.out.println("Lets proceed to payment.");
System.out.println();
trs_obj.payment(total_fare);
System.out.println();
System.out.println("Find your ticket details below.");
System.out.println();
System.out.println("Full Name " + "\t" +"Gender" + "\t" + "Age" + "\t" + "Quota" + "\t" + "Coach" + "\t" + "Fare");
for(int i=0;i<user_arr.length;i++)
{
user_arr[i].user_head.gender=u_obj.gender(user_arr[i].user_head.gender);
user_arr[i].user_head.quota=u_obj.quota(user_arr[i].user_head.quota);
user_arr[i].user_head.coach_type=u_obj.coach_type(user_arr[i].user_head.coach_type);
double fare=u_obj.ticket_fare(user_arr[i].user_head,u_obj.ticket_fare(valid_arr.get(j).head, source, destination, user_arr[i].user_head.quota));
u_obj.show(user_arr[i].user_head);
System.out.print(fare);
System.out.println();
}
System.out.println();
System.out.println("Total payment done of INR " + total_fare);
System.out.println();
System.out.println("Your train details are as follows: ");
System.out.println();
System.out.println("Boarding from : " + source);
System.out.println("Destination : " + destination);
t_obj.show_train_details(valid_arr.get(j).head);
System.out.println();
System.out.println("Have a Safe and Happy Journey.");
}//end of user login
void agent()//agent login
{
Test_RailwaySystem trs_obj=new Test_RailwaySystem();//object of Test_RailwaySystem
User_Details u_obj=new User_Details();//object of User_Details
Train_details t_obj=new Train_details();//object of Train_details
Administration_Login adm_obj=new Administration_Login();//object of Administration_Login
Agent_Login a_login=new Agent_Login();//object of Agent_Login
Train_details[] arr=t_obj.forward_journey();//original list of trains
Scanner sc=new Scanner(System.in);
System.out.println();
u_obj.get_captcha();
System.out.println();
System.out.println("You have access to Agent Login");
System.out.println();
System.out.println("You can book upto 12 tickets at a time.");
System.out.println("10% extra charges will be applicable on each ticket.");
System.out.println();
System.out.println("Following is list of trains:");//displaying list of trains
for(int i=0;i<arr.length-1;i++)
{
System.out.print(arr[i].head.PNR_NO + "\t");
t_obj.show(arr[i].head);
System.out.println();
}
System.out.println();
System.out.print("Enter from where you want to board the train: ");
String source=sc.nextLine();
System.out.print("Enter your destination: ");
String destination=sc.nextLine();
System.out.println();
System.out.println("Available trains are: ");
ArrayList<Train_details> valid_arr=u_obj.check_source_destination(source, destination);
u_obj.valid_trains(valid_arr);
System.out.println();
System.out.print("Enter Train Number in which you want to travel: ");
long book_train=sc.nextLong();
u_obj.make_bst(valid_arr, book_train);
int j=u_obj.valid_train_index(valid_arr, book_train);
System.out.println();
System.out.println("You have chosen the following train: ");
System.out.print(valid_arr.get(j).head.PNR_NO + "\t");
u_obj.show(valid_arr.get(j).head);
System.out.println();
System.out.println();
int no_of_tickets=a_login.no_of_tickets();
System.out.println();
User_Details[] user_arr=u_obj.user_details(no_of_tickets);
System.out.println();
System.out.println("Following are passenger details entered and their corresponding ticket fares.");
System.out.println("Full Name " + "\t" +"Gender" + "\t" + "Age" + "\t" + "Quota" + "\t" + "Coach" + "\t" + "Fare");
double total_fare=0;
for(int i=0;i<user_arr.length;i++)
{
user_arr[i].user_head.gender=u_obj.gender(user_arr[i].user_head.gender);
user_arr[i].user_head.quota=u_obj.quota(user_arr[i].user_head.quota);
user_arr[i].user_head.coach_type=u_obj.coach_type(user_arr[i].user_head.coach_type);
double fare=u_obj.ticket_fare(user_arr[i].user_head,u_obj.ticket_fare(valid_arr.get(j).head, source, destination, user_arr[i].user_head.quota));
u_obj.show(user_arr[i].user_head);
System.out.print(fare);
System.out.println();
total_fare+=fare;
}
System.out.println();
System.out.println("Actual fare is: " + total_fare);
double extra_fare=0.1*total_fare;
System.out.println("10% of Actual fare is(Extra charges) : " + Math.round(extra_fare*100)/100.0);
total_fare=a_login.extra_charges(total_fare);
total_fare=Math.round(total_fare*100)/100.0;//rounding off total fare to two decimal places
System.out.println("Total fare to be paid is : " + total_fare);
System.out.println("Lets proceed to payment.");
System.out.println();
trs_obj.payment(total_fare);
System.out.println("Find your ticket details below.");
System.out.println("Full Name " + "\t" +"Gender" + "\t" + "Age" + "\t" + "Quota" + "\t" + "Coach" + "\t" + "Fare");
for(int i=0;i<user_arr.length;i++)
{
user_arr[i].user_head.gender=u_obj.gender(user_arr[i].user_head.gender);
user_arr[i].user_head.quota=u_obj.quota(user_arr[i].user_head.quota);
user_arr[i].user_head.coach_type=u_obj.coach_type(user_arr[i].user_head.coach_type);
double fare=u_obj.ticket_fare(user_arr[i].user_head,u_obj.ticket_fare(valid_arr.get(j).head, source, destination, user_arr[i].user_head.quota));
u_obj.show(user_arr[i].user_head);
System.out.print(fare);
System.out.println();
}
System.out.println();
System.out.println("Total payment done of INR " + total_fare);
System.out.println();
System.out.println("Your train details are as follows: ");
System.out.println();
System.out.println("Boarding from : " + source);
System.out.println("Destination : " + destination);
t_obj.show_train_details(valid_arr.get(j).head);
System.out.println();
System.out.println("Have a Safe and Happy Journey.");
}//end of agent login
public static void main(String[] args)
{
Test_RailwaySystem trs_obj=new Test_RailwaySystem();//object of Test_RailwaySystem
User_Details u_obj=new User_Details();//object of User_Details
Train_details t_obj=new Train_details();//object of Train_details
Administration_Login adm_obj=new Administration_Login();//object of Administration_Login
Agent_Login a_login=new Agent_Login();//object of Agent_Login
int login_type=trs_obj.accept_login();
Train_details[] arr=t_obj.forward_journey();//original list of trains
Scanner sc=new Scanner(System.in);
switch(login_type)//switch loop based on login_type
{
case 1:trs_obj.administration();//administration login
break;//end of administration login
case 2:
trs_obj.user();//user login
break;//end of user login
case 3:trs_obj.agent();//agent login
break;//end of agent login
case 4:System.out.println("You have chosen to exit");
System.out.println("......Thank you......");
System.exit(0);
break;
}
}
}