0% found this document useful (0 votes)
118 views28 pages

Railways Project

This document contains information about a computer project on railways including a certificate page, acknowledgements, and theory section on relevant Java packages and classes used for input/output streams and file handling. The coding section includes code to take user input for passenger details like name, address, date of birth, train number, destination stations, and number of tickets. It then checks validity of input and calculates ticket fares.

Uploaded by

Aditya Joshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
118 views28 pages

Railways Project

This document contains information about a computer project on railways including a certificate page, acknowledgements, and theory section on relevant Java packages and classes used for input/output streams and file handling. The coding section includes code to take user input for passenger details like name, address, date of birth, train number, destination stations, and number of tickets. It then checks validity of input and calculates ticket fares.

Uploaded by

Aditya Joshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 28

Railways

Index

S.No. Contents Page No.

Certificate 2

2 Acknowledgement 3

3 Theory 4

4 Coding 5

5 Output 26

6 Conclusion 27

1
Railways

CERTIFICATE

This is to certify that this Computer Project which is submitted by

“Miss Akanksha " X t h C in lieu partial fulfillment of the requirement

of Indian Certificate of Secondary Education (ICSE BOARD) by

I.S.C Examination Affiliated to New Delhi is record of their work

carried out by them.

Principal In Charge of Computer Department

Sr. Jyotis Mr. Pradeep Atri

2
Railways

Acknowledgement

Lastly I conclude that the program given for this project is an


overall summary of Java with in one program. Though it took sometime
to complete this project, but I really enjoyed preparing this project. I
could complete the theory portion easily but the coding part of the
project was a bit difficult. However, I overcame this difficulty with the
support of my computer teacher. I consulted my computer book for
preparing this project.

It is a noble chance to express my gratitude to all those who helped


me in completing this computer project.
It is a great pleasure for me to express my deep sense of respect
and gratitude to Sr. Jyotis, Principal, St. Mary's School, Najibabad.
I'm also thankful to Mr. Pradeep Atri for his regular and kind support
during this project. I’m very thankful to my family members for providing
me their precious suggestions.
I'm very thankful to Mr. Pradeep Atri for supporting and
encouraging me to make this computer Project.

“Miss Akanksha"

3
Railways

Theory

Java is a purely Object Oriented programming language and platform


independent. Java is a trademark or registered trademark of Sun
Microsystems, Inc. in the US and other countries.

Package java.io Description

Provides for system input and output through data streams, serialization and the
file system.

DataInputStream
A data input stream lets an application read primitive Java data types from an
underlying input stream in a machine-independent way.

DataOutputStream
A data input stream lets an application write primitive Java data types to an
output stream in a portable way

FileInputStream
A FileInputStream obtains input bytes from a file in a file system

FileOutputStream
A file output stream is an output stream for writing data to a File or to a
FileDescriptor.

BufferedReader
Read text from a character-input stream, buffering characters so as to provide for

the efficient reading of characters, arrays, and lines.

4
Railways

Coding
import java.io.*;

import java.util.*;

public class rails

String

tr[]={"SM","Sheldah","tendawn","chandigarh","doon","janta","link","rajdhani"};

String

na[]={"MUM","KOL","LKN","MOR","NBD","DEL","SHR","LXR","THR","KOT","FAR

","HAR","MRT"};

int ch[]={900,800,150,60,100,66,52,70,950,4,122,45,97};

int tn[]={1234,656,3645,4788,7886,123,465,6699};

int z[]=new int[90];

int f[]={25,50,100,147,250,78,90,43};

int t[]={6,22,7,11,9,13,5,19};

int

b99=0,a111=0,a7=0,t1=0,t2=0,k1=0,a6=0,z1=0,z2=0,V=1,p=0,m,d1,c=0,d,y,n1,j=

0,w=0,n2,i,n3,n4,n5,n6,s9,a,b,d3,k,pnrstatus;

String q,q5,s,s1,s2,s3,s4,s8,s5="",s10,s100;

boolean bx=false;

DataInputStream in=new DataInputStream(System.in);

public void seat()throws Exception

5
Railways
try{

FileReader frs =new FileReader("personalidentificationdetails.mp3");

BufferedReader brs =new BufferedReader(frs);

brs.close();

frs.close();

}catch(Exception awa)

{ FileWriter fw12 = new FileWriter("personalidentificationdetails.mp3");

PrintWriter pw12=new PrintWriter(fw12);

pw12.print(0);

pw12.close();

fw12.close();

FileWriter fw = new FileWriter("q.txt",true);

BufferedWriter bw=new BufferedWriter(fw);

PrintWriter pw=new PrintWriter(bw);

System.out.print("\n\n\n\n\n");

System.out.print("WELCOME TO RESEVATION:-\n \n");

System.out.print("ENTER YOUR INFORMATION:-\n\n Name:-\n");

s10=in.readLine();

System.out.print("\n Address:-\n");

s1=in.readLine();

System.out.print("\n D/O/B:-\n Month:-\n");

m=Integer.parseInt(in.readLine());

System.out.print("\n date:-\n");

d1=Integer.parseInt(in.readLine());
6
Railways
System.out.print("\n year:-\n");

y=Integer.parseInt(in.readLine());

Date d= new Date();

System.out.println(d);

if(y%4!=0)

if(m>12)

c=1;

System.out.println("date is invalid");

if(m==4||m==6||m==9||m==11)

if(d1>30)

c=1;

System.out.print("date is invalid");

if(m==2)

if(d1>28)

c=1;

System.out.print("date is invalid");

7
Railways
}

if(m==1||m==3||m==5||m==7||m==8||m==10||m==12)

if(d1>31)

c=1;

System.out.print("date is invalid");

if(y%4==0)

if(m==4||m==6||m==9||m==11)

if(d1>30)

c=1;

System.out.print("date is invalid");

if(m==2)

if(d1>29)

8
Railways
c=1;

System.out.print("date is invalid");

if(m==1||m==3||m==5||m==7||m==8||m==10||m==12)

if(d1>31)

System.out.println("date is invalid");

int c=1;

System.out.print("\n");

if(c==1)

System.out.print("DATE IS INVALID");

if(c==0)

System.out.println("\n\n");

System.out.println("TRAIN NAME\t- TRAIN NUMBER");

for(i=0;i<8;i++)

9
Railways
System.out.print(tr[i]+"-"+tn[i]+"\n");

System.out.println("\n\n\nENTER YOUR TRAIN NUMBER BY WHICH YOU

WANT TO GO:-");

n2=Integer.parseInt(in.readLine());

int f2=0;

for(k=0;k<8;k++)

if(tn[k]==n2)

p=k;

f2=1;

System.out.println(" \n\nENTER YOUR CHOICE STATION \n\n ");

System.out.println(" MUM :- MUMBAI ");

System.out.println(" KOL :- KOLKATA ");

System.out.println(" LKN :- LUCKNOW ");

System.out.println(" MOR :- MORADABAD ");

System.out.println(" NBD :- NAJIBABAD ");

System.out.println(" DEL :- NEW DELHI ");

System.out.println(" SHR :- SAHARANPUR ");

System.out.println(" LXR :- LUXUR ");

System.out.println(" THR :- THIRUVANTHAMPURAM ");

System.out.println(" KOT :- KOTDWAR ");

System.out.println(" FAR :- FARIDABAD ");

System.out.println(" HAR :- HARIDWAR ");

10
Railways
System.out.println(" MRT :- MEERUT ");

System.out.print("\nENTER YOUR TOWN/CITY FROM WHERE YOU WANT

TO GO:-\n");

s3=in.readLine();

System.out.print("\nENTER YOUR DESTINATION TO WHERE YOU WANT TO

GO:-\n");

s4=in.readLine();

for(i=0;i<13;i++)

if(s3.equalsIgnoreCase("MUM")&&s4.equalsIgnoreCase(na[i]))

V=0;

w=ch[i];

if(s3.equalsIgnoreCase("MUM")&&s4.equalsIgnoreCase(na[i]))

V=0;

w=ch[i];

if(s3.equalsIgnoreCase("KOL")&&s4.equalsIgnoreCase(na[i]))

V=0;

w=ch[i];

if(s3.equalsIgnoreCase("LKN")&&s4.equalsIgnoreCase(na[i]))

11
Railways
{

V=0;

w=ch[i];

if(s3.equalsIgnoreCase("MOR")&&s4.equalsIgnoreCase(na[i]))

V=0;

w=ch[i];

if(s3.equalsIgnoreCase("NBD")&&s4.equalsIgnoreCase(na[i]))

V=0;

w=ch[i];

if(s3.equalsIgnoreCase("DEL")&&s4.equalsIgnoreCase(na[i]))

V=0;

w=ch[i];

if(s3.equalsIgnoreCase("SHR")&&s4.equalsIgnoreCase(na[i]))

V=0;

w=ch[i];

if(s3.equalsIgnoreCase("LXR")&&s4.equalsIgnoreCase(na[i]))

12
Railways
{

V=0;

w=ch[i];

if(s3.equalsIgnoreCase("THR")&&s4.equalsIgnoreCase(na[i]))

V=0;

w=ch[i];}

if(s3.equalsIgnoreCase("KOT")&&s4.equalsIgnoreCase(na[i]))

V=0;

w=ch[i];

if(s3.equalsIgnoreCase("FAR")&&s4.equalsIgnoreCase(na[i]))

V=0;

w=ch[i];

if(s3.equalsIgnoreCase("HAR")&&s4.equalsIgnoreCase(na[i]))

V=0;

w=ch[i];

if(s3.equalsIgnoreCase("MRT")&&s4.equalsIgnoreCase(na[i]))

13
Railways
V=0;

w=ch[i];

if(V==1)

System.out.println("INVALID CODE");

if(V==0)

System.out.print("ENTER NUMBER OF ADULT:-\n");

n3=Integer.parseInt(in.readLine());

a=n6+n3;

System.out.print("ENTER NUMBER OF CHILDREN:-\n");

n4=Integer.parseInt(in.readLine());

b=a+n4;

n5++;

n6++;

FileReader frs =new FileReader("personalidentificationdetails.mp3");

BufferedReader brs =new BufferedReader(frs);

pnrstatus=Integer.parseInt(brs.readLine());

brs.close();

frs.close();

pnrstatus+=1;

FileWriter fw12 = new FileWriter("personalidentificationdetails.mp3");

PrintWriter pw12=new PrintWriter(fw12);

pw12.print(pnrstatus);
14
Railways
pw12.close();

fw12.close();

System.out.println("\n\nseat is reserved in s"+n5+" from "+n6+" to "+b);

t1=n6;

t2=b;

System.out.println(" \n\nTICKET IS PRINTING\n\n\n\n");

System.out.println("* train name:="+tr[p]+" "+"train no."+tn[p]+"

PNR NO. => "+pnrstatus+"\n ");

System.out.println("* no.of children :- "+n4+"\n ");

System.out.println("* no.of adult :- "+n3 +"\n" );

System.out.println("* compartment:- s"+n5 + "\n

");

System.out.println("* Seat no.:- "+t1+" to "+t2+" "+"time:-"+t[p]

+"hrs. \n");

System.out.println("* Charges are:- "+(w*(n4+n3))

+"Rs. \n\n ");

System.out.println(" "+" HAPPY JOURNEY");

pw.println("PNR NO. "+pnrstatus);

pw.println("Train No. "+tn[p]);

pw.println("Name "+s10);

pw.println("ADDRESS "+s1);

pw.println("DATE "+Integer.toString(m)

+"\\"+Integer.toString(d1)+"\\"+Integer.toString(y));

pw.println("ADULTS "+n3);

15
Railways
pw.println("CHILDREN "+n4);

pw.println("COMPARTMENT "+n5);

pw.println("SEAT NO." +n6+" to "+b);

pw.close();

FileWriter fwr = new FileWriter("y.txt");

BufferedWriter bwr=new BufferedWriter(fwr);

PrintWriter pwr=new PrintWriter(bwr);

pwr.println(b);

pwr.close();

if(f2==0)

System.out.println("TRAIN NUMBER IS INVALID");

public void anarchy() throws Exception

int a71=0;

FileReader fr =new FileReader("y.txt");

BufferedReader br =new BufferedReader(fr);

System.out.println("SEAT EMPTY ARE");

a71=Integer.parseInt(br.readLine());

for(i=(a71+1);i<=90;i++)

16
Railways
System.out.print(i+"\t");

System.out.println();

public void trainsearch()

System.out.println("TRAIN NAME\t\tTRAIN NO.\t\thrs");

for(i=0;i<8;i++)

System.out.println(tr[i]+"\t\t"+tn[i]+"\t\t\t"+t[i]+" "+"hrs");

public void reservedseat()throws Exception

String s="";

if(a111==1)

FileReader frz=new FileReader("qz.txt");

BufferedReader brz=new BufferedReader(frz);

String q2;

while((q2=brz.readLine())!=null)

System.out.println(q2);

17
Railways
}

else

FileReader fr=new FileReader("q.txt");

BufferedReader br=new BufferedReader(fr);

while((s=br.readLine())!=null)

System.out.println(s);

public void enquiry()

System.out.println("ENTER YOUR CHOICE FOR CHOICE\n\n");

System.out.println("1- CHECK AC COMPARTMENT");

System.out.println("2- PLATFORM");

System.out.println("3- TIME OF TRAIN");

System.out.println("4- PRESENT TIME");

try{s9=Integer.parseInt(in.readLine());}catch(Exception exc){}

switch(s9)

case 1:

System.out.println("THE AC COMPARTMENTS ARE AS:-\n\n");

System.out.println("TRAIN NAME TRAIN NO.");

for(i=1;i<8;i++)

18
Railways
{

System.out.println(tr[i]+" "+tn[i]);

break;

case 2:

for(i=0;i<8;i++)

if(i%2==0)

System.out.println("TRAIN NAME IS "+tr[i]+" PLATFORM IS "+1);

else

System.out.println("TRAIN NAME IS "+tr[i]+" PLATFORM IS "+2);

break;

case 3:

System.out.println("TRAIN NAME TRAIN NO. TRAIN TIME");

for(i=0;i<8;i++)

System.out.println(tr[i]+"\t\t"+tn[i]+"\t\t"+t[i]+" "+"0'clock\t\t");

break;

case 4:

System.out.println("THE DATE IS ");

Date d3=new Date();

System.out.println(d3);

break;

19
Railways
default:

System.out.println("INVALID INPUT");

public void cancel()throws Exception

bx=true;

int pnrcancel;

System.out.print("ENTER THE VALID PNR NO. =>");

pnrcancel=Integer.parseInt(in.readLine());

FileReader frwz=new FileReader("q.txt");

BufferedReader brwz=new BufferedReader(frwz);

while((q5=brwz.readLine())!=null)

if(q5.equalsIgnoreCase("PNR NO. "+pnrcancel))

a111=1;

b99=0;

break;

else

b99=1;

20
Railways
}

if(b99==1)

b99=0;

System.out.println("INVALID PNR NO. OR YOUR TICKET IS ALREADY

CANCELLED... ");

else

FileWriter fwz1 = new FileWriter("qz.txt",true);

BufferedWriter bwz1=new BufferedWriter(fwz1);

PrintWriter pwz1=new PrintWriter(bwz1);

pwz1.println(q5);

pwz1.close();

String temp;

FileReader frd =new FileReader("q.txt");

BufferedReader brd =new BufferedReader(frd);

FileWriter fwz11 = new FileWriter("temps.txt");

PrintWriter pwz11=new PrintWriter(fwz11);

while((temp=brd.readLine())!=null)

if(temp.equalsIgnoreCase("PNR NO. "+pnrcancel))

brd.readLine();brd.readLine();brd.readLine();brd.readLine();brd.readLine();brd.rea

dLine();brd.readLine();brd.readLine();

21
Railways
}

else

pwz11.println(temp);

pwz11.close();

fwz11.close();

brd.close();

frd.close();

fwz11 = new FileWriter("q.txt");

pwz11=new PrintWriter(fwz11);

frd =new FileReader("temps.txt");

brd =new BufferedReader(frd);

while((temp=brd.readLine())!=null)

pwz11.println(temp);

pwz11.close();

fwz11.close();

brd.close();

frd.close();

File fgh=new File("temps.txt");

22
Railways
fgh.delete();

System.out.println("THE TICKET IS CANCELED\n\n");

public void exit()

System.exit(0);

public static void main(String arg[])throws Exception

char b=5,chr;

int ch;

DataInputStream in=new DataInputStream(System.in);

do

System.out.print("*********************************WELCOME***********************

*****************\n");

System.out.print("************************************TO******************************

************\n");

System.out.print("*****************************RAILWAY

RESERVATION********************************\n");

System.out.print(" \n");

System.out.print(" SELECT YOUR CHOICE

\n");

System.out.print(" \n");

23
Railways
System.out.print("1 - SEAT RESERVATION

\n");

System.out.print("2 - ANARCHY OF SEAT

\n");

System.out.print("3 - TRAIN

SEARCH \n");

System.out.print("4 - RESERVERED SEAT

\n");

System.out.print("5 - ENQUIRY \n");

System.out.print("6 - CANCELLATION

\n");

System.out.print("7 - EXIT \n");

System.out.print("\n");

try

ch=Integer.parseInt(in.readLine());

} catch(Exception ee)

ch=Integer.parseInt(in.readLine());

rails rw = new rails();

if(ch==1)

rw.seat();

if(ch==2)

24
Railways
rw.anarchy();

if(ch==3)

rw.trainsearch();

if(ch==4)

rw.reservedseat();

if(ch==5)

rw.enquiry();

if(ch==7)

rw.exit();

if(ch==6)

rw.cancel();

System.out.println("Do you want to continue press y ");

chr= (char) System.in.read();

}while(chr=='Y' || chr=='y');

OUTPUT

25
Railways
*********************************WELCOME*****************************
***********

************************************TO*********************************
*********

*****************************RAILWAY
RESERVATION*************
*******************

SELECT YOUR CHOICE

1- SEAT RESERVATION

2- ANARCHY OF SEAT

3- TRAIN SEARCH

4- RESERVERED SEAT

5- ENQUIRY

6- CANCELLATION

Enter your choice(1 to 6)………

CONCLUSION

26
Railways

Lastly, I conclude that the program given for this project is an overall

summary of java with in one program. Though it took some time to complete this

project, but I really enjoyed myself while preparing this project. I could complete

the theory portion easily but the coding part of the project was a bit difficult

without the support of computer sir.

27
Railways

28

You might also like