Structure Query Language, C programming, Java, Servlet, Jsp, Unix

Sunday 15 July 2012

Booking a railway ticket, Reservation


[ reservation.java ]
import java.io.*;
class ticket
{
int tot_psnger=0,age[];
static int pnr_no;
String name[],gender[],source,destination,jdate,preority[];
public void book_ticket() throws IOException
{
pnr_no=300000;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter Source : ");
source=br.readLine();
System.out.print("Enter destination : ");
destination=br.readLine();
System.out.print("Enter Journey Date : ");
jdate=br.readLine();
System.out.print("Enter Total Passengers : ");
tot_psnger=Integer.parseInt(br.readLine());

while(tot_psnger<=0)
{
System.out.println("Number of Passengers must be greater then zero....");
System.out.print("Enter Total Passengers : ");
tot_psnger=Integer.parseInt(br.readLine());
}

name=new String[tot_psnger];
gender=new String[tot_psnger];
preority=new String[tot_psnger];
age=new int[tot_psnger];
int i=0;
while(i<tot_psnger)
{
pnr_no++;
System.out.print("Enter Name : ");
name[i]=br.readLine();
System.out.print("Enter Age : ");
age[i]=Integer.parseInt(br.readLine());
System.out.print("Enter Gender : ");
gender[i]=br.readLine();
System.out.print("Enter Preority (MD:Middle Birth, UP:Upper Birth, LB:Lower Birth, SL:Side Lower, SU: Side Upper )");
preority[i]=br.readLine();
i++;
}
}
public void display_ticket()
{

int i=0;
System.out.println("===========================================================\n");
System.out.println("\tPNR NO : "+ pnr_no);
System.out.println("\tSource : "+source+"   ,  Destination : " + destination);
System.out.println("\tJourney Date : "+ jdate);
System.out.println("\n===========================================================\n");
System.out.print("S.NO.\tNAME   AGE\tGENDER \tPREORITY \n");
System.out.println("=====\t====   ===\t====== \t========\n");
while(i<tot_psnger)
{
System.out.println(i+1 + "\t" + name[i] + "\t" + age[i] + "\t" +gender[i] + "\t" +preority[i]+"\n");
i++;
}
System.out.println("===========================================================");
}
}
class reservation
{
public static void main(String args[]) throws IOException
{
ticket obj;
obj=new ticket();
obj.book_ticket();
obj.display_ticket();
}
}

6 comments:

  1. GoTo Command Prompt(Win + R)

    HOW TO COMPILE
    javac c:\yourdir\reservation.java

    HOW TO EXECUTE
    java c:\yourdir\reservation

    ReplyDelete
  2. showing error while executing......"Main method not found in class ticket, please define the main method as : public static void main(String[] args)

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  3. the official said for instance, if a passenger wants information about his train running irctc ticket availability

    ReplyDelete
  4. Hi,
    For the Great information you write it very clean. I am very lucky to get this tips from you.very well information you write it very clean. I’m very lucky to get this information from you .

    irctc login registration
    irctc ticket booking online

    ReplyDelete
  5. Nice information. With modernization of Indian Railways, it is easier to print railway ticket .

    ReplyDelete