0% found this document useful (0 votes)
61 views6 pages

Newjk

This Java code implements a train reservation system with different classes (1st, 2nd, 3rd) and sleeper seats. It allows the user to select a class, enter their name, and see their assigned seat number. The user can also view the current status/occupancy of all seats. Arrays track the booked seats in each class, and messages notify the user if all seats in a class are booked already.

Uploaded by

Harshit Agrawal
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views6 pages

Newjk

This Java code implements a train reservation system with different classes (1st, 2nd, 3rd) and sleeper seats. It allows the user to select a class, enter their name, and see their assigned seat number. The user can also view the current status/occupancy of all seats. Arrays track the booked seats in each class, and messages notify the user if all seats in a class are booked already.

Uploaded by

Harshit Agrawal
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 6

PROJECT CODE

package javalib; import javax.swing.JOptionPane; import javax.swing.JTextArea; public class reservation1 { public static String ac_first_class[]=new String[10]; public static String ac_2nd_class[]=new String[10]; public static String ac_3rd_class[]=new String[10]; public static String sleeper[]=new String[10]; public static void main(String args[]) {

String output="Enter 1 for ac_first_class\n"+"Enter 2 for ac_2nd_class\n"+"Enter 3 for ac_3rd_class\n"+"Enter 4 for sleeper\n"+"Enter 5 for show seat info\n"+"Enter 6 for exit\n"; JOptionPane.showMessageDialog(null,output,"ReservationSystem",JOptionPane.INFORMATION_ME SSAGE); int i=0,j=0,k=0,l=0; String ch=JOptionPane.showInputDialog("Enter a choice"); int choice=Integer.parseInt(ch); while(choice !=6) { switch(choice) { case 1: if(i>10 )

{ JOptionPane.showMessageDialog(null,"All seats are book in ac_first_class section"+" Do u want a seat in sleeper"); break;} ac_first_class(i); i++; break; case 2: if(j>10){ JOptionPane.showMessageDialog(null,"All seats are book in ac_2nd_class section"+"Do u want a seat in ac"); break;} ac_2nd_class(j); j++; break; case 3: if(k>10) { JOptionPane.showMessageDialog(null,"All seats are book in ac_3rd_class section"+"Do u want a seat in ac"); break; } ac_3rd_class(k); k++; break; case 4: if(l>10)

{ JOptionPane.showMessageDialog(null,"All seats are book in sleeper section"+"Do u want a seat in ac"); break; } sleeper(l); l++; break; case 5: status(); break; default: JOptionPane.showMessageDialog(null,"You enter awrong choice"+"enteragain"); } ch=JOptionPane.showInputDialog("Enter a choicen"); choice=Integer.parseInt(ch); } System.exit(0); } public static void ac_first_class(int x) { /* { break; }*/ String name=JOptionPane.showInputDialog("Enter passsenger name"); ac_first_class[x]=name; if(x>4)

int y=x; String output="\npassenger name--"+name+"\nseat no--"+(y+1)+"\nac_first_class section"; JOptionPane.showMessageDialog(null,output,"Boarding Pass",JOptionPane.INFORMATION_MESSAGE); } public static void ac_2nd_class(int q) { /* break; }*/ String name=JOptionPane.showInputDialog("Enter passsenger name"); ac_2nd_class[q]=name; int y=q; String output="\npassenger name--"+name+"\nseat no--"+(y+1)+"\nac_2nd_class section"; JOptionPane.showMessageDialog(null,output,"Boarding Pass",JOptionPane.INFORMATION_MESSAGE); } public static void ac_3rd_class(int r) { /* break; }*/ String name=JOptionPane.showInputDialog("Enter passsenger name"); ac_3rd_class[r]=name; int y=r; String output="\npassenger name--"+name+"\nseat no--"+(y+1)+"\nac_3rd_class if(x>4){ if(x>4){

section"; JOptionPane.showMessageDialog(null,output,"Boarding Pass",JOptionPane.INFORMATION_MESSAGE); } public static void sleeper(int y) { String name=JOptionPane.showInputDialog("Enter passenger name"); sleeper[y]=name; int z=y; String output="passenger name--"+name+"\nseat no--"+(z+1)+"\nsleeper section"; JOptionPane.showMessageDialog(null,output,"BoardingPass",JOptionPane.INFORMATI ON_MESSAGE); } public static void status() { int t; JTextArea outputArea=new JTextArea(20,30); outputArea.append("seat_no sleeper"); for( t=0;t<10;t++) outputArea.append("\n"+" "+(t+1)+" "+" "+ac_first_class[t]+" "+ac_2nd_class[t]+" "+ac_3rd_class[t]+" "+sleeper[t]+" "+"\n"); ac_first_class ac_2nd_class ac_3rd_class

JOptionPane.showMessageDialog(null,outputArea,"seatinfo",JOptionPane.INFORMATION_MESSAGE) } }

You might also like