Saturday, November 1, 2014

Railway Ticket Reservation (Booking) Program – ICSE Project On BlueJ



 This can be a project work for ICSE students. In this program the operator will enter the name, age, address etc of the passengers and  ticket will be issued with coach number, berth number, fare etc. In this program we will use only five routes (like: Howrah to Tatanagar), only one date and number of tickets can be issued maximum 100. (In real life project, database is used and any route and any date tickets can be issued.)


import java.io.*;
class RailwayTicket
{
 int i,x=0,index=0,w=0;
  int c=0;
 String names[], address[], contact[],gender[];
 String wnames[], waddress[], wcontact[],wgender[];
 String stations[]={"Howrah", "Burdwan", "Asansol","Dhanbad","Tatanagar"};
 int distance[]={0,100,200,250,350};
 int age[],wage[];
   String ans, start,end;
 String fare[]={"Howrah - Burdwan - 60", "Howrah - Asansol - 110", "Howrah - Dhanbad - 160", "Howrah - Tatanagar - 200" ,"Burdwan - Asansol - 60" ,"Burdwan - Dhanbad - 110" ,"Burdwan - Tatanagar - 160" , "Asansol - Dhanbad - 60","Asansol - Tatanagar - 110", "Dhanbad - Tatanagar - 60"};


 // FOR SECOND TRAIN

 String names2[], address2[], contact2[],gender2[];
 String wnames2[], waddress2[], wcontact2[],wgender2[];
 String stations2[]={"Howrah", "Burdwan", "Gaya","Ayodhya","Jammu Tawi"};
 int distance2[]={0,100,200,250,350};
 int age2[],wage2[];
   String ans2, start2,end2;
 String fare2[]={"Howrah - Burdwan - 60", "Howrah - Gaya - 110", "Howrah -Ayodhya- 360", "Howrah -Jammu Tawi - 580" ,"Burdwan - Gaya - 60" ,"Burdwan - Ayodhya - 310" ,"Burdwan - Jammu Tawi - 460" , "Gaya - Ayodhya- 160","Gaya - Jammu Tawi - 310", "Ayodhya - Jammu Tawi - 260"};


 //FOR THIRD TRAIN

 String names3[], address3[], contact3[],gender3[];
 String wnames3[], waddress3[], wcontact3[],wgender3[];
 String stations3[]={"Howrah", "Liluah", "Burdwan","Durgapur","Ondal"};
 int distance3[]={0,100,200,250,350};
 int age3[],wage3[];
   String ans3, start3,end3;
 String fare3[]={"Howrah - Liluah - 60", "Howrah - Burdwan - 110", "Howrah - Durgapur - 160", "Howrah -Ondal- 200" ," Liluah- Burdwan - 60" ,"Liluah - Durgapur - 110" ,"Liluah - Ondal - 160" , " Burdwan-Durgapur  - 60","Burdwan - Ondal - 110", "Durgapur - Ondal- 60"};

 // FOR FOURTH TRAIN

 String names4[], address4[], contact4[],gender4[];
 String wnames4[], waddress4[], wcontact4[],wgender4[];
 String stations4[]={"Srinagar","Katra","Jammu Tawi", "Ludhiana","Amritsar"};
 int distance4[]={0,100,200,250,350};
 int age4[],wage4[];
   String ans4, start4,end4;
 String fare4[]={"Srinagar- Katra - 60", " Srinagar- Jammu Tawi - 110", "Srinagar - Ludhiana - 160", " Srinagar- Amritsar - 200" ," Katra- Jammu Tawi - 60" ,"Katra -Ludhiana  - 110" ,"Katra -Amritsar  - 160" , " Jammu Tawi-Ludhiana  - 60","Jammu Tawi - Amritsar - 110", " Ludhiana-Amritsar  - 60"};

 // FOR FIFTH TRAIN

 String names5[], address5[], contact5[],gender5[];
 String wnames5[], waddress5[], wcontact5[],wgender5[];
 String stations5[]={"Howrah", "Kharagpur", "Khoddar","Bhubaneshwar","Puri"};
 int distance5[]={0,100,200,250,350};
 int age5[],wage5[];
   String ans5, start5,end5;
 String fare5[]={"Howrah - Kharagpur - 160", "Howrah - Khoddar - 210", "Howrah -Bhubaneshwar  - 270", "Howrah - Puri - 350" ,"Kharagpur -Khoddar  - 160" ,"Kharagpur -Bhubaneshwar  - 210" ," Kharagpur- Puri - 300" , "Khoddar - Bhubaneshwar - 160","Khoddar - Puri - 210", " Bhubaneshwar-Puri- 160"};

2017 ISC Computer Application Paper Suggestion: CLICK HERE

  BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  int booked[]=new int[100];
 int booked2[]=new int[100];
int booked3[]=new int[100];
 int booked4[]=new int[100];
 int booked5[]=new int[100];
  RailwayTicket()
  {
      names=new String[100];
      address=new String[100];
      contact=new String[100];
      gender=new String[100];
      age=new int[100];
     
      wnames=new String[100];
      waddress=new String[100];
      wcontact=new String[100];
      wgender=new String[100];
      wage=new int[100];
      for(int i=0;i< 100;i++)
       booked[i]=-1;
      
       // second train
      
       names2=new String[100];
      address2=new String[100];
      contact2=new String[100];
      gender2=new String[100];
      age2=new int[100];
     
      wnames2=new String[100];
      waddress2=new String[100];
      wcontact2=new String[100];
      wgender2=new String[100];
      wage2=new int[100];
      for(int i=0;i< 100;i++)
       booked2[i]=-1;
      
       //third
      
       names3=new String[100];
      address3=new String[100];
      contact3=new String[100];
      gender3=new String[100];
      age3=new int[100];
     
      wnames3=new String[100];
      waddress3=new String[100];
      wcontact3=new String[100];
      wgender3=new String[100];
      wage3=new int[100];
      for(int i=0;i< 100;i++)
       booked3[i]=-1;
      
      
       // fourth
      
       names4=new String[100];
      address4=new String[100];
      contact4=new String[100];
      gender4=new String[100];
      age4=new int[100];
     
      wnames4=new String[100];
      waddress4=new String[100];
      wcontact4=new String[100];
      wgender4=new String[100];
      wage4=new int[100];
      for(int i=0;i< 100;i++)
       booked4[i]=-1;
      
      
      
       // fifth
      
       names5=new String[100];
      address5=new String[100];
      contact5=new String[100];
      gender5=new String[100];
      age5=new int[100];
     
      wnames5=new String[100];
      waddress5=new String[100];
      wcontact5=new String[100];
      wgender5=new String[100];
      wage5=new int[100];
      for(int i=0;i< 100;i++)
       booked5[i]=-1;
       
      
    }
    public void takeData() throws Exception
    {
       int train;
      
       System.out.println("Enter 1 for Tatanagar Mail , 2 for Jammu Tawi \n 3 for Mayurakshi, 4 for Punjab Mail AND 5 for Puri Mail");
       train=Integer.parseInt(br.readLine());
       if (train==1)
       first();
       else if(train==2)
       second();
      else if(train==3)
       third();
       else if(train==4)
       fourth();
      else if(train==5)
       fifth();



        }
   
        void first() throws Exception
        {
           
      
       System.out.print("\nStaring Station:");
       for(i=0;i< stations.length;i++)
       System.out.print("    "+stations[i]);
              System.out.print(" :");
       start=br.readLine();
      
      System.out.print("\nEnding Station:");
       for(i=0;i< stations.length;i++)
       System.out.print("    "+stations[i]);
              System.out.print(" :");
       end=br.readLine();
       start=start + " - "+ end;
         while(true)
         {
             System.out.print("\nName:");
             names[x]=br.readLine();
             if(c==0)
             {
             System.out.print("\nAddress:");
             address[x]=br.readLine();
            }
            else
            address[x]=address[x-1];
             System.out.print("\nAge:");
            age[x]=Integer.parseInt(br.readLine());
            System.out.print("\nGender:");
             gender[x]=br.readLine();
             c++;
             x++;
             if(c==6)
             break;
             System.out.print("\nAny More Member (y/n):");
             ans=br.readLine();
             if(ans.equalsIgnoreCase("N"))
             break;
            }
         
         show1();
  
        }
        void second() throws Exception
        {
            
      
       System.out.print("\nStaring Station:");
       for(i=0;i< stations2.length;i++)
       System.out.print("    "+stations2[i]);
              System.out.print(" :");
       start2=br.readLine();
      
      System.out.print("\nEnding Station:");
       for(i=0;i< stations2.length;i++)
       System.out.print("    "+stations2[i]);
              System.out.print(" :");
       end2=br.readLine();
       start2=start2 + " - "+ end2;
         while(true)
         {
             System.out.print("\nName:");
             names2[x]=br.readLine();
             if(c==0)
             {
             System.out.print("\nAddress:");
             address2[x]=br.readLine();
            }
            else
            address2[x]=address2[x-1];
             System.out.print("\nAge:");
            age2[x]=Integer.parseInt(br.readLine());
            System.out.print("\nGender:");
             gender2[x]=br.readLine();
             c++;
             x++;
             if(c==6)
             break;
             System.out.print("\nAny More Member (y/n):");
             ans=br.readLine();
             if(ans.equalsIgnoreCase("N"))
             break;
            }
         
         show2();
  
        }
       
        void third() throws Exception
        {
           
           
      
       System.out.print("\nStaring Station:");
       for(i=0;i< stations3.length;i++)
       System.out.print("    "+stations3[i]);
              System.out.print(" :");
      
       start3=br.readLine();
      
      System.out.print("\nEnding Station:");
       for(i=0;i< stations3.length;i++)
       System.out.print("    "+stations3[i]);
       System.out.print(" :");
       end3=br.readLine();
       start3=start3 + " - "+ end3;
         while(true)
         {
             System.out.print("\nName:");
             names3[x]=br.readLine();
             if(c==0)
             {
             System.out.print("\nAddress:");
             address3[x]=br.readLine();
            }
            else
            address3[x]=address3[x-1];
             System.out.print("\nAge:");
            age3[x]=Integer.parseInt(br.readLine());
            System.out.print("\nGender:");
             gender3[x]=br.readLine();
             c++;
             x++;
             if(c==6)
             break;
             System.out.print("\nAny More Member (y/n):");
             ans=br.readLine();
             if(ans.equalsIgnoreCase("N"))
             break;
            }
         
         show3();
  
        }
       
       
       
        void fourth() throws Exception
       
        {
           
      
       System.out.print("\nStaring Station:");
       for(i=0;i< stations4.length;i++)
       System.out.print("    "+stations4[i]);
              System.out.print(" :");
       start4=br.readLine();
      
      System.out.print("\nEnding Station:");
       for(i=0;i< stations4.length;i++)
       System.out.print("    "+stations4[i]);
              System.out.print(" :");
       end4=br.readLine();
       start4=start4 + " - "+ end4;
         while(true)
         {
             System.out.print("\nName:");
             names4[x]=br.readLine();
             if(c==0)
             {
             System.out.print("\nAddress:");
             address4[x]=br.readLine();
            }
            else
            address4[x]=address4[x-1];
             System.out.print("\nAge:");
            age4[x]=Integer.parseInt(br.readLine());
            System.out.print("\nGender:");
             gender4[x]=br.readLine();
             c++;
             x++;
             if(c==6)
             break;
             System.out.print("\nAny More Member (y/n):");
             ans=br.readLine();
             if(ans.equalsIgnoreCase("N"))
             break;
            }
         
         show4();
  
        }
       
       
        void fifth() throws Exception
        {
           
      
       System.out.print("\nStaring Station:");
       for(i=0;i< stations5.length;i++)
       System.out.print("    "+stations5[i]);
              System.out.print(" :");
       start5=br.readLine();
      
      System.out.print("\nEnding Station:");
       for(i=0;i< stations5.length;i++)
       System.out.print("    "+stations5[i]);
              System.out.print(" :");
       end5=br.readLine();
       start5=start5 + " - "+ end5;
         while(true)
         {
             System.out.print("\nName:");
             names5[x]=br.readLine();
             if(c==0)
             {
             System.out.print("\nAddress:");
             address5[x]=br.readLine();
            }
            else
            address5[x]=address5[x-1];
             System.out.print("\nAge:");
            age5[x]=Integer.parseInt(br.readLine());
            System.out.print("\nGender:");
             gender5[x]=br.readLine();
             c++;
             x++;
             if(c==6)
             break;
             System.out.print("\nAny More Member (y/n):");
             ans=br.readLine();
             if(ans.equalsIgnoreCase("N"))
             break;
            }
         
         show5();
  
        }
    void show1() throws Exception
    {
       String s;
       int famt1=0,famt=0;
       index=0;
            
        for(i=0;i<  fare.length;i++)
        {
          s=fare[i];
          index=s.lastIndexOf("-");
          famt1=Integer.parseInt(s.substring(index+1).trim());
          s=s.substring(0,index).trim();
       // System.out.println(s+ " \n  "+famt1 + "\n"+start);
          if(start.equalsIgnoreCase(s))
         
          break;
        }

       
     for(i=0;i< 100;i++)
     {
          if(booked[i]< 0)
          index++;
        }
         if (x >index)
         {
             System.out.println("No Berth...\nWant waiting list ticket?(y/n):");
            
         ans=br.readLine();
         if(!ans.equalsIgnoreCase("N"))
         {
              System.out.println("\nSouth Eastern Railway\n");
            System.out.println("\nWaiting List Tickets\n");
            System.out.println("\nName            Address      Age   Gender   Fare(Rs.)  Waiting No\n");
            for(i=x-c;i< x;i++)
            {
                wnames[w]=names[i];
                waddress[w]=address[i];
                wage[w]=age[i];
                wgender[w]=gender[i];
                w++;
              //  System.out.println("Age="+age[i]);
                if(age[i]< =12)
                {
                famt+=famt1/2;
                  System.out.println(names[i]+"            "+address[i]+"      "+age[i]+"   "+gender[i]+ "   "+(famt1/2)+ " "+w);
                }
                else
                   {
                famt+=famt1;
                  System.out.println(names[i]+"            "+address[i]+"      "+age[i]+"   "+gender[i]+ "   "+famt1+ " "+w);
                }
            }
           
           System.out.println("Total (Rs.)"+ famt);
                        System.out.println("In Words Rs:"+ numToWord(famt));
         
           
              x=x-c;
            }
        }
        else
        {
             System.out.println("\nSouth Eastern Railway\n");
            System.out.println("\nConfirmed Tickets\n");
            System.out.println("\nName            Address      Age   Gender    Fare (Rs.)  Berth No\n");
             for(i=x-c;i< x;i++)
             {
                for(int j=0;j< 100;j++)
                {
                     if(booked[j]==-1)
                     booked[j]=0;
                     break;
                    }      
                  //  famt+=famt1;
                if(age[i]< =12)
                {
                famt+=famt1/2;
                  System.out.println(names[i]+"            "+address[i]+"      "+age[i]+"   "+gender[i]+ "   "+(famt1/2)+ " "+w);
                }
                else
                   {
                famt+=famt1;
                  System.out.println(names[i]+"            "+address[i]+"      "+age[i]+"   "+gender[i]+ "   "+famt1+ " "+w);
                }
               
            }
             System.out.println("Total (Rs.)"+ famt);
                          System.out.println("In Words Rs:"+ numToWord(famt));
        }
          c=0;
    }
   
   
        void show2() throws Exception
    {
       String s;
       int famt1=0,famt=0;
       index=0;
            
        for(i=0;i<  fare2.length;i++)
        {
          s=fare2[i];
          index=s.lastIndexOf("-");
          famt1=Integer.parseInt(s.substring(index+1).trim());
          s=s.substring(0,index).trim();
       // System.out.println(s+ " \n  "+famt1 + "\n"+start);
          if(start2.equalsIgnoreCase(s))
         
          break;
        }

       
     for(i=0;i< 100;i++)
     {
          if(booked2[i]< 0)
          index++;
        }
         if (x >index)
         {
             System.out.println("No Berth...\nWant waiting list ticket?(y/n):");
            
         ans=br.readLine();
         if(!ans.equalsIgnoreCase("N"))
         {
              System.out.println("\nSouth Eastern Railway\n");
            System.out.println("\nWaiting List Tickets\n");
            System.out.println("\nName            Address      Age   Gender   Fare(Rs.)  Waiting No\n");
            for(i=x-c;i< x;i++)
            {
                wnames2[w]=names2[i];
                waddress2[w]=address2[i];
                wage2[w]=age2[i];
                wgender2[w]=gender2[i];
                w++;
               if(age2[i]< =12)
                {
                famt+=famt1/2;
                  System.out.println(names2[i]+"            "+address2[i]+"      "+age2[i]+"   "+gender2[i]+ "   "+(famt1/2)+ " "+w);
                }
                else
                   {
                famt+=famt1;
                  System.out.println(names2[i]+"            "+address2[i]+"      "+age2[i]+"   "+gender2[i]+ "   "+famt1+ " "+w);
                }
            }
           
           System.out.println("Total (Rs.)"+ famt);
                        System.out.println("In Words Rs:"+ numToWord(famt));
         
           
              x=x-c;
            }
        }
        else
        {
             System.out.println("\nSouth Eastern Railway\n");
            System.out.println("\nConfirmed Tickets\n");
            System.out.println("\nName            Address      Age   Gender    Fare (Rs.)  Berth No\n");
             for(i=x-c;i< x;i++)
             {
                for(int j=0;j< 100;j++)
                {
                     if(booked2[j]==-1)
                     booked2[j]=0;
                     break;
                    }      
                    if(age2[i]< =12)
                {
                famt+=famt1/2;
                  System.out.println(names2[i]+"            "+address2[i]+"      "+age2[i]+"   "+gender2[i]+ "   "+(famt1/2)+ " "+w);
                }
                else
                   {
                famt+=famt1;
                  System.out.println(names2[i]+"            "+address2[i]+"      "+age2[i]+"   "+gender2[i]+ "   "+famt1+ " "+w);
                }
            }
             System.out.println("Total (Rs.)"+ famt);
                          System.out.println("In Words Rs:"+ numToWord(famt));
        }
          c=0;
    }

        void show3() throws Exception
    {
       String s;
       int famt1=0,famt=0;
       index=0;
            
        for(i=0;i<  fare3.length;i++)
        {
          s=fare3[i];
          index=s.lastIndexOf("-");
          famt1=Integer.parseInt(s.substring(index+1).trim());
          s=s.substring(0,index).trim();
       // System.out.println(s+ " \n  "+famt1 + "\n"+start);
          if(start3.equalsIgnoreCase(s))
         
          break;
        }

       
     for(i=0;i< 100;i++)
     {
          if(booked3[i]< 0)
          index++;
        }
         if (x >index)
         {
             System.out.println("No Berth...\nWant waiting list ticket?(y/n):");
            
         ans=br.readLine();
         if(!ans.equalsIgnoreCase("N"))
         {
              System.out.println("\nSouth Eastern Railway\n");
            System.out.println("\nWaiting List Tickets\n");
            System.out.println("\nName            Address      Age   Gender   Fare(Rs.)  Waiting No\n");
            for(i=x-c;i< x;i++)
            {
                wnames3[w]=names3[i];
                waddress3[w]=address3[i];
                wage3[w]=age3[i];
                wgender3[w]=gender3[i];
                w++;
                if(age3[i]< =12)
                {
                famt+=famt1/2;
                  System.out.println(names3[i]+"            "+address3[i]+"      "+age3[i]+"   "+gender3[i]+ "   "+(famt1/2)+ " "+w);
                }
                else
                   {
                famt+=famt1;
                  System.out.println(names3[i]+"            "+address3[i]+"      "+age3[i]+"   "+gender3[i]+ "   "+famt1+ " "+w);
                }
            }
           
           System.out.println("Total (Rs.)"+ famt);
                        System.out.println("In Words Rs:"+ numToWord(famt));
         
           
              x=x-c;
            }
        }
        else
        {
             System.out.println("\nSouth Eastern Railway\n");
            System.out.println("\nConfirmed Tickets\n");
            System.out.println("\nName            Address      Age   Gender    Fare (Rs.)  Berth No\n");
             for(i=x-c;i< x;i++)
             {
                for(int j=0;j< 100;j++)
                {
                     if(booked3[j]==-1)
                     booked3[j]=0;
                     break;
                    }      
                   if(age3[i]< =12)
                {
                famt+=famt1/2;
                  System.out.println(names3[i]+"            "+address3[i]+"      "+age3[i]+"   "+gender3[i]+ "   "+(famt1/2)+ " "+w);
                }
                else
                   {
                famt+=famt1;
                  System.out.println(names3[i]+"            "+address3[i]+"      "+age3[i]+"   "+gender3[i]+ "   "+famt1+ " "+w);
                }
            }
             System.out.println("Total (Rs.)"+ famt);
                          System.out.println("In Words Rs:"+ numToWord(famt));
        }
          c=0;
    }

    void show4() throws Exception
    {
       String s;
       int famt1=0,famt=0;
       index=0;
            
        for(i=0;i<  fare4.length;i++)
        {
          s=fare4[i];
          index=s.lastIndexOf("-");
          famt1=Integer.parseInt(s.substring(index+1).trim());
          s=s.substring(0,index).trim();
       // System.out.println(s+ " \n  "+famt1 + "\n"+start);
          if(start4.equalsIgnoreCase(s))
         
          break;
        }

       
     for(i=0;i< 100;i++)
     {
          if(booked4[i]< 0)
          index++;
        }
         if (x >index)
         {
             System.out.println("No Berth...\nWant waiting list ticket?(y/n):");
            
         ans=br.readLine();
         if(!ans.equalsIgnoreCase("N"))
         {
              System.out.println("\nSouth Eastern Railway\n");
            System.out.println("\nWaiting List Tickets\n");
            System.out.println("\nName            Address      Age   Gender   Fare(Rs.)  Waiting No\n");
            for(i=x-c;i< x;i++)
            {
                wnames4[w]=names4[i];
                waddress4[w]=address4[i];
                wage4[w]=age4[i];
                wgender4[w]=gender4[i];
                w++;
               if(age4[i]< =12)
                {
                famt+=famt1/2;
                  System.out.println(names4[i]+"            "+address4[i]+"      "+age4[i]+"   "+gender4[i]+ "   "+(famt1/2)+ " "+w);
                }
                else
                   {
                famt+=famt1;
                  System.out.println(names4[i]+"            "+address4[i]+"      "+age4[i]+"   "+gender4[i]+ "   "+famt1+ " "+w);
                }
            }
           
           System.out.println("Total (Rs.)"+ famt);
                   System.out.println("In Words Rs:"+ numToWord(famt));   
           
              x=x-c;
            }
        }
        else
        {
             System.out.println("\nSouth Eastern Railway\n");
            System.out.println("\nConfirmed Tickets\n");
            System.out.println("\nName            Address      Age   Gender    Fare (Rs.)  Berth No\n");
             for(i=x-c;i< x;i++)
             {
                for(int j=0;j< 100;j++)
                {
                     if(booked4[j]==-1)
                     booked4[j]=0;
                     break;
                    }      
                    if(age4[i]< =12)
                {
                famt+=famt1/2;
                  System.out.println(names4[i]+"            "+address4[i]+"      "+age4[i]+"   "+gender4[i]+ "   "+(famt1/2)+ " "+w);
                }
                else
                   {
                famt+=famt1;
                  System.out.println(names4[i]+"            "+address4[i]+"      "+age4[i]+"   "+gender4[i]+ "   "+famt1+ " "+w);
                }
            }
             System.out.println("Total (Rs.)"+ famt);
            System.out.println("In Words Rs:"+ numToWord(famt));
        }
          c=0;
    }
   
        void show5() throws Exception
    {
       String s;
       int famt1=0,famt=0;
       index=0;
            
        for(i=0;i<  fare5.length;i++)
        {
          s=fare5[i];
          index=s.lastIndexOf("-");
          famt1=Integer.parseInt(s.substring(index+1).trim());
          s=s.substring(0,index).trim();
       // System.out.println(s+ " \n  "+famt1 + "\n"+start);
          if(start5.equalsIgnoreCase(s))
         
          break;
        }

       
     for(i=0;i< 100;i++)
     {
          if(booked5[i]< 0)
          index++;
        }
         if (x >index)
         {
             System.out.println("No Berth...\nWant waiting list ticket?(y/n):");
            
         ans=br.readLine();
         if(!ans.equalsIgnoreCase("N"))
         {
              System.out.println("\nSouth Eastern Railway\n");
            System.out.println("\nWaiting List Tickets\n");
            System.out.println("\nName            Address      Age   Gender   Fare(Rs.)  Waiting No\n");
            for(i=x-c;i< x;i++)
            {
                wnames5[w]=names5[i];
                waddress5[w]=address5[i];
                wage5[w]=age5[i];
                wgender5[w]=gender5[i];
                w++;
                if(age5[i]< =12)
                {
                famt+=famt1/2;
                  System.out.println(names5[i]+"            "+address5[i]+"      "+age5[i]+"   "+gender5[i]+ "   "+(famt1/2)+ " "+w);
                }
                else
                   {
                famt+=famt1;
                  System.out.println(names5[i]+"            "+address5[i]+"      "+age5[i]+"   "+gender5[i]+ "   "+famt1+ " "+w);
                }
            }
            
           System.out.println("Total (Rs.)"+ famt);
           System.out.println("In Words Rs:"+ numToWord(famt));
         
           
              x=x-c;
            }
        }
        else
        {
             System.out.println("\nSouth Eastern Railway\n");
            System.out.println("\nConfirmed Tickets\n");
            System.out.println("\nName            Address      Age   Gender    Fare (Rs.)  Berth No\n");
             for(i=x-c;i< x;i++)
             {
                for(int j=0;j< 100;j++)
                {
                     if(booked5[j]==-1)
                     booked5[j]=0;
                     break;
                    }      
                    if(age5[i]< =12)
                {
                famt+=famt1/2;
                  System.out.println(names5[i]+"            "+address5[i]+"      "+age5[i]+"   "+gender5[i]+ "   "+(famt1/2)+ " "+w);
                }
                else
                   {
                famt+=famt1;
                  System.out.println(names5[i]+"            "+address5[i]+"      "+age5[i]+"   "+gender5[i]+ "   "+famt1+ " "+w);
                }
            }
             System.out.println("Total (Rs.)"+ famt);
             System.out.println("In Words Rs:"+ numToWord(famt));
        }
          c=0;
    }
   
    String numToWord(int n)
    {
         String str="";
         int zero=0,i,rev=0,n1;
         n1=n;
         while(true)
         {
              if(n%10==0)
              zero++;
              else
              break;
              n=n/10;
            }
            n=n1;
            for(i=n;i >0;i=i/10)
            {
                 rev=rev*10+i%10;
                }
                while(rev >0)
                {
                     switch(rev%10)
                     {
                         case 0:
                         str=str + " Zero";
                         break;
                         case 1:
                         str=str + " One";
                         break;
                         case 2:
                         str=str + " Two";
                         break;
                         case 3:
                         str=str + " Three";
                         break;
                         case 4:
                         str=str + " Four";
                         break;
                         case 5:
                         str=str + " Five";
                         break;
                         case 6:
                         str=str + " Six";
                         break;
                         case 7:
                         str=str + " Seven";
                         break;
                         case 8:
                         str=str + " Eight";
                         break;
                         case 9:
                         str=str + " Nine";
                         break;
                        }
                        rev=rev/10;
                    }
         for(i=0;i< zero;i++)
         str=str+ " Zero";
         return str;
        }

    public static void main(String args[])throws Exception
    {
         BufferedReader br1=new BufferedReader(new InputStreamReader(System.in));
         RailwayTicket ob=new RailwayTicket();
         char ch;
         while(true)
         {
              ob.takeData();
              System.out.println("Any More(y/n):");
              ch=(char)br1.read();
              ch=Character.toLowerCase(ch);
              if(ch=='n')
              break;
            }
        }
    }



Variable Description



Type
Variable Name
Purpose
Scope
String
names []
To store name of passenger
Entire program
String
address []
To store address of passenger
Entire program
String
contact []
To store contact number of passenger
Entire program
String
gender []
To store gender of passenger
Entire program
String
names2 []
To store name of passenger
Entire program
String
address2 []
To store address of passenger
Entire program
String
contact2 []
To store contact number of passenger
Entire program
String
gender2 []
To store gender of passenger
Entire program
String
names3 []
To store name of passenger
Entire program
String
address3 []
To store address of passenger
Entire program
String
contact3 []
To store contact number of passenger
Entire program
String
gender3 []
To store gender of passenger
Entire program
String
names4 []
To store name of passenger
Entire program
String
address4 []
To store address of passenger
Entire program
String
contact4 []
To store contact number of passenger
Entire program
String
gender4 []
To store gender of passenger
Entire program
String
stations []
To store station names
Entire program
String
fare []
To store fare of different locations
Entire program

2 comments:

  1. couldn't b compiled because of this entry-- if(age[i]< =12)
    please suggest a correct answer.urgent.

    ReplyDelete
    Replies
    1. Actually the statement should be 'age[i]<=12' not 'age[i]< =12)'. Angular brackets are treated as html tag that's why a space is set while posting the program

      Delete

Subscribe via email

Enter your email address:

Delivered by FeedBurner