Important alert: (current site time 10/24/2014 3:24:06 AM EDT)
 

VB icon

RAILWAY RESERVATION

Email
Submitted on: 9/27/2007 4:49:30 AM
By: SHASHANK SOLANKI  
Level: Advanced
User Rating: By 5 Users
Compatibility: C#, VB.NET, ASP.NET, C++.NET
Views: 51463
(About the author)
 
     YOU CAN BOOK,CANCEL,VIEW TICKETS HISTORY
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: RAILWAY RESERVATION
// Description:YOU CAN BOOK,CANCEL,VIEW TICKETS HISTORY
// By: SHASHANK SOLANKI
//
// Assumes:FIRSTLY DOWNLOAD JDK FILE AND BLUEJ TO USE THE APPLICATION
//
// Side Effects:NO ``
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=5997&lngWId=10//for details.//**************************************

/* PROJECT ON:railway reservation
COMPILED BY :shashank
CLASS AND DIVISION:X
ROLL NO.: ddd
PROJECT STARTED ON:9/12/2006 Time: 7:00 p.m.
PROJECT ENDED ON :
DESCRIPTION : To Book / Cancel ticket, Display reservation chart, 
Search passenger number, And exit.
 */
import java.io.*;
public class reservation
{
InputStreamReader isr=new InputStreamReader (System.in);
BufferedReader br=new BufferedReader (isr);
//System.out.print("Please enter a word");
int pno[]=new int[275];
String name[]=new String[275];
String phno[]=new String[275];
int age[]=new int[275];
int cl[]=new int[275];
int pcount=0;
int pnum=1;
int max1=75;
int max2=125;
int max3=175;
 public void doMenu() throws Exception
{
int cho=0;
do
{
System.out.println("\f");
doHeading();
System.out.println("1.Book ticket");
System.out.println("2.Cancel ticket");
System.out.println("3.Search passenger");
System.out.println("4.Reservation chart");
System.out.println("5.Display unbooked tickets");
System.out.println("6.Exit");
System.out.println("Please enter your choice");
cho=Integer.parseInt(br.readLine());
switch(cho)
{
case 1:doBook();
break;
case 2:doCancel();
break;
case 3:doSearch();
break;
case 4:doDispList();
break;
case 5:doDispUnbooked();
break;
case 6:doExit();
break;
default :System.out.println("Invalid choice");
}
char e=(char)br.read();
}while(cho!=6);
}
private void doHeading()throws Exception
{
System.out.println("#########################################################");
System.out.println("*********Railway Reservation For Kabul Express***********");
System.out.println("#########################################################");
}
private void doBook()throws Exception
{
System.out.println("Please enter the class of ticket");
System.out.println("1. AC\t 2. First\t 3. Sleeper\t");
int c=Integer.parseInt(br.readLine());
System.out.println("Please enter no. of tickets");
int t=Integer.parseInt(br.readLine());
int ticketAvailable=0;
if(c==1 && max1>=t)
{
ticketAvailable=1;
}
if(c==2 && max2>=t)
{
ticketAvailable=1;
}
if(c==3 && max3>=t)
{
ticketAvailable=1;
}
if(ticketAvailable==1)
{
for(int i=0;i<t;i++)
{
pno[pcount]=pnum;
System.out.println("Please enter your name");
name[pcount]=br.readLine();
System.out.println("Please enter your age");
age[pcount]=Integer.parseInt(br.readLine());
cl[pcount]=c;
System.out.println("Please enter your phno");
phno[pcount]=br.readLine();
pcount++;
pnum++;
System.out.println("Ticket successfully booked");
}//for
if(c==1)
{
max1-=t;
System.out.println("Please pay Rs."+t*1500);
}
if(c==2)
{
max2-=t;
System.out.println("Please pay Rs."+t*1200);
}
if(c==3)
{
max3-=t;
System.out.println("Please pay Rs."+t*1000);
}
}
}
private void doCancel()throws Exception
{
int t_pno[]=new int[275];
String t_name[]=new String[275];
String t_phno[]=new String[275];
int t_age[]=new int[275];
int t_cl[]=new int[275];
int t_pcount=0;
int passengerFound=0;
System.out.println("Please enter your passenger no.");
int p=Integer.parseInt(br.readLine());
for(int i=0;i<pcount;i++)
{
if(pno[i]!=p)
{//transfer
t_pno[t_pcount]=pno[i];
t_name[t_pcount]=name[i];
t_phno[t_pcount]=phno[i];
t_age[t_pcount]=age[i];
t_cl[t_pcount]=cl[i];
t_pcount++;
}
else
{
passengerFound=1;
if(cl[i]==1)
{
max1++;
System.out.println("Please collect refund of Rs."+1800);
}
if(cl[i]==2)
{
 max2++;
System.out.println("Please collect refund of Rs."+1500);
}
 if(cl[i]==3)
 {
 max3++;
System.out.println("Please collect refund of Rs."+1000);
}//else
}//if
}
if(passengerFound==1)
{
pno=t_pno;
name=t_name;
age=t_age;
cl=t_cl;
phno=t_phno;
pcount=t_pcount;
System.out.println("ticket successfully cancelled");
 }
}//method
private void doDispList()throws Exception
{
System.out.println("Passenger list in AC class");
System.out.println("pno \t name \t\t age \t phno");
for(int i=0;i<pcount;i++)
{
if(cl[i]==1)
{
System.out.println(pno[i]+"\t"+name[i]+"\t\t"+age[i]+"\t"+phno[i]);
}
}
System.out.println("Passenger list in First class");
System.out.println("pno \t name \t\t age \t phno");
 for(int i=0;i<pcount;i++)
 {
if(cl[i]==2)
{
System.out.println(pno[i]+"\t"+name[i]+"\t\t"+age[i]+"\t"+phno[i]);
}
}
System.out.println("Passenger list in Sleeper class");
System.out.println("pno \t name \t\t age \t phno");
 for(int i=0;i<pcount;i++)
 {
if(cl[i]==3)
{
System.out.println(pno[i]+"\t"+name[i]+"\t\t"+age[i]+"\t"+phno[i]);
}
}
}
private void doSearch()throws Exception
{
int passengerFound=0;
System.out.println("Please enter passenger no. to search");
int p=Integer.parseInt(br.readLine());
for(int i=0;i<pcount;i++)
{
if(pno[i]==p)
{
System.out.println("Detail found");
passengerFound=1;
 System.out.println("passenger no.="+pno[i]); 
 System.out.println("name="+name[i]);
 System.out.println("class="+cl[i]); 
 System.out.println("phno="+phno[i]);
System.out.println("age="+age[i]);
}
}//for
if(passengerFound==0)
System.out.println("No such passenger");
}//method
private void doDispUnbooked()throws Exception
{
System.out.println("No. of booked tickets status");
System.out.println("AC class"+max1);
System.out.println("First class"+max2);
System.out.println("Sleeper class"+max3);
}
private void doExit()
{
System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
System.out.println("Name : Yash , Class : X, Roll No. : 13");
System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
}
}


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

1/2/2008 7:49:34 PM laokim

Please post complete application.
Thank you.
(If this comment was disrespectful, please report it.)

 
1/18/2009 2:14:28 AMjuna

thank's for your code...
(If this comment was disrespectful, please report it.)

 
3/6/2009 2:53:40 PMJigar

Hey frnd,
this code is for java application nah
or it too works in vb.net
(If this comment was disrespectful, please report it.)

 
9/26/2011 3:05:32 PMAli Chaudhary

please upload full app
(If this comment was disrespectful, please report it.)

 
10/6/2011 1:27:36 PMtarun

can u pls give the decription of the variables used
(If this comment was disrespectful, please report it.)

 
10/7/2011 1:13:54 AMakanksha :)

thanx a lot for ur help......!!
plz can u write the variable description also :)
(If this comment was disrespectful, please report it.)

 
10/21/2011 1:18:33 PMrahul

Exception in thread "main" java.lang.NoClassDefFoundError: reservation.class

fake code
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.