-
Notifications
You must be signed in to change notification settings - Fork 0
/
RAILWAY.java
293 lines (272 loc) · 14.2 KB
/
RAILWAY.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
import java.io.*;
import java.util.Random;
public class RAILWAY
{
public static void main(String args[])throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in= new BufferedReader(read);
String train[]={"12024","JANSHATABDI EXP","PATNA JN","PNBE","05:30","PATNA SAHEB","PNC","05:46","MOKAMEH JN","MKA","06:40","HATHIDAH JN","HTZ","06:48","LUCKEESARAI JN","LKR","07:12","JAMUI","JMU","07:38","JHAJHA","JAJ","08:21","JASIDIH JN","JSME","08:56","MADHUPUR JN","MDP","09:22","JAMTARA","JMT","09:52","CHITTARANJAN","CRJ","10:08","ASANSOL JN","ASN","10:43","DURGAPUR","DGR","11:17","HOWRAH JN","HWH","13:25"};
int i,ch,nop=0,prn=0,prnu,k=0,m=0,sn=0,dn=0,rate=0,num=0;
String pn[]=new String[10];
String pa[]=new String[10];
String ps[]=new String[10];
int psn[]=new int[10];
String User_id,password,cl="",doj="",dtn="",src="",ans,tm="",str="";
System.out.println(" Welcome To Railway reservation Terminal ");
System.out.println("User_id:-");
User_id=in.readLine();
System.out.println("Password:-");
password=in.readLine();
if(User_id.equals("admin")&&password.equals("admin"))
{
while(true)
{
System.out.println("1 Book Ticket");
System.out.println("2 Enqiury Train");
System.out.println("3 Print Ticket");
System.out.println("4 Cancel ticket");
System.out.println("5 Log out");
System.out.println("Enter The Option Range (1-5)");
ch=Integer.parseInt(in.readLine());
Random ran = new Random();
if(ch==1)
{
prn=ran.nextInt(10)+456826;
m=ran.nextInt(10);
System.out.println("Enter The Journey Details");
System.out.println("Please Switch On Caps Lock Button ");
System.out.println("Enter The Date Of Journey (DD-MM-YEAR) ");
doj=in.readLine();
System.out.println("Enter The Source Station");
src=in.readLine();
System.out.println("Enter The Destination Station");
dtn=in.readLine();
System.out.println("Enter The Class(SL,1AC,2AC,3AC)");
cl=in.readLine();
if(cl.equals("SL"))
{
rate=1000;
}
if(cl.equals("1AC"))
{
rate=3000;
}
if(cl.equals("2AC"))
{
rate=2500;
}
if(cl.equals("3AC"))
{
rate=2000;
}
System.out.println("Enter The Number of Passenger Excluding child(below<12)");
nop=Integer.parseInt(in.readLine());
num=rate*nop;
String a[]={"","one","two","three","four","five","six","seven","eight","nine","ten","eleven","tweleve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty","twentyone","twentytwo","twentythree","twentyfour","twentyfive","twentysix","twentyseven","twentyeight","twentynine","thirty","thirtyone","thirtytwo","thirtythree","thirtyfour","thirtyfive","thirtysix","thirtyseven","thirtyeight","thirtynine","fourty","fourtyone","fourtytwo","fourtythree","fourtyfour","fourtyfive","fourtysix","fourtyseven","fourtyeight","fourtynine","fifty","fiftyone","fiftytwo","fiftythree","fiftyfour","fiftyfive","fiftysix","fiftyseven","fiftyeight","fiftynine","sixty","sixtyone","sixtytwo","sixtythree","sixtyfour","sixtyfive","sixtysix","sixtyseven","sixtyeight","sixtynine","seventy","seventyone","seventytwo","seventythree","seventyfour","seventyfive","seventysix","seventyseven","seventyeight","seventynine","eighty","eightyone","eightytwo","eightythree","eightyfour","eightyfive","eightysix","eightyseven","eightyeight","eightynine","ninty","nintyone","nintytwo","nintythree","nintyfour","nintyfive","nintysix","nintyseven","nintyeight","nintynine"};
int l,p1,p2,p3,p;
String name=num+"";
l=name.length();
if(l==4||l==5)
{
p1=num/1000;
for(i=0;i<100;i++)
{
if(i==p1&&p1!=0)
{
str=str+a[i]+" thousand";
}
}
p2=(num%1000)/100;
for(i=0;i<100;i++)
{
if(i==p2&&p2!=0)
{
str=str+" "+a[i]+" hundred";
}
}
p3=(num%1000)%100;
for(i=0;i<100;i++)
{
if(i==p3&&p3!=0)
{
str=str+" and "+a[i]+" only";
}
}
}
if(l==6||l==7)
{
p=num/100000;
for(i=0;i<100;i++)
{
if(i==p&&p!=0)
{
str=str+a[i]+" lac";
}
}
p1=num%100000;
p1=p1/1000;
for(i=0;i<100;i++)
{
if(i==p1&&p1!=0)
{
str=str+" "+a[i]+" thousand";
}
}
p2=(num%1000)/100;
for(i=0;i<100;i++)
{
if(i==p2&&p2!=0)
{
str=str+" "+a[i]+" hundred";
}
}
p3=(num%1000)%100;
for(i=0;i<100;i++)
{
if(i==p3&&p3!=0)
{
str=str+" and "+a[i];
}
}
}
for(i=0;i<nop;i++)
{
System.out.println("Enter The "+(i+1)+" Passenger Name");
pn[i]=in.readLine();
System.out.println("Enter The "+(i+1)+" Passenger Age");
pa[i]=in.readLine();
System.out.println("Enter The "+(i+1)+" Passenger Sex");
ps[i]=in.readLine();
psn[i]=ran.nextInt(6) + 41;
}
for(i=0;i<44;i++)
{
if(train[i].equals(src))
{
src=train[i-1];
tm=train[i+1];
}
if(train[i].equals(dtn))
{
dtn=train[i-1];
}
}
System.out.println(" Successfully Booked Ticket ");
System.out.println("PNR : "+prn);
System.out.println("Train Name :"+train[1]);
System.out.println("Train Number: "+train[0]);
System.out.println("Boarding Station : "+src+" "+"Destination Station : "+dtn);
System.out.println("Date of Journey :"+doj);
System.out.println("Arrival Time: "+tm);
System.out.println("Coach :"+cl+""+m);
System.out.println("Sno "+'\t'+"Name "+'\t'+"Age "+'\t'+"Sex"+'\t'+"Seat No");
for(i=0;i<nop;i++)
{
k=i+1;
System.out.println((k)+" "+'\t'+pn[i]+" "+'\t'+pa[i]+'\t'+ps[i]+'\t'+psn[i]);
}
System.out.println("Amount in word:- "+str+" only");
}
if(ch==2)
{
System.out.println(" E-Ticket Query Terminal ");
System.out.println("Enter The Date Journey:");
doj=in.readLine();
System.out.println("Enter The Source station :");
src=in.readLine();
System.out.println("Enter The Destination Station :");
dtn=in.readLine();
for(i=0;i<44;i++)
{
if(train[i].equals(src))
{
sn=1;
tm=train[i+1];
}
if(train[i].equals(dtn))
{
dn=1;
}
}
if(dn==1&&sn==1)
{
System.out.println(" Your Search Results ");
System.out.println("Journey Date :"+doj);
System.out.println("Arrival time :"+tm);
System.out.println("Train Number: "+train[0]);
System.out.println("Train Name: "+train[1]);
System.out.println("Source Station: "+src);
System.out.println("Destination Station: "+dtn);
}
else
{
System.out.println("Sorry No Train Matched Of Your Choice ");
}
}
if(ch==3)
{
k=0;
System.out.println(" E-Tecket Print Terminal ");
System.out.println("Enter The PNR: ");
prnu=Integer.parseInt(in.readLine());
if(prnu==prn)
{
System.out.println(" E-Ticket Details ");
System.out.println("PNR : "+prn);
System.out.println("Train Name :"+train[1]);
System.out.println("Train Number: "+train[0]);
System.out.println("Boarding Station : "+src+" "+"Destination Station : "+dtn);
System.out.println("Date of Journey :"+doj);
System.out.println("Arrival Time: "+tm);
System.out.println("Coach :"+cl+""+m);
System.out.println("Sno "+'\t'+"Name "+'\t'+"Age "+'\t'+"Sex"+'\t'+"Seat No");
for(i=0;i<nop;i++)
{
k=i+1;
System.out.println((k)+" "+'\t'+pn[i]+" "+'\t'+pa[i]+'\t'+ps[i]+'\t'+psn[i]);
}
System.out.println("Amount in word:- "+str+" only");
}
}
if(ch==4)
{
System.out.println(" E-Ticket Cancel Terminal ");
System.out.println("Do You Sure Want To Cancel E-Ticket ?Y or N");
ans=in.readLine();
if(ans.equals("Y"))
{
System.out.println("Enter The PRN: ");
prnu=Integer.parseInt(in.readLine());
if(prnu==prn)
{
for(i=0;i<nop;i++)
{
pn[i]="";
pa[i]="";
ps[i]="";
psn[i]=0;
prn=0;
}
System.out.println("Your Ticket Has Been Successfully cancel");
}
}
else
{
System.out.println("NO Record Found");
}
if(ans.equals("N"))
{
continue;
}
}
if(ch==5)
{
System.out.println("Logging Out Successfully");
System.out.println("Thank You ");
break;
}
}
}
}
}