0% found this document useful (0 votes)
39 views

Java Assignment: Bachelor in Technology (Information Technology)

This document contains the code for a Java program that implements a railway reservation system. It includes classes for managing reservation details like passenger names and seat bookings, displaying the reservation status and booking seats. The main method initializes objects and gets user input for train details, passenger details and reservation date before displaying the booked seats and reservation details.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Java Assignment: Bachelor in Technology (Information Technology)

This document contains the code for a Java program that implements a railway reservation system. It includes classes for managing reservation details like passenger names and seat bookings, displaying the reservation status and booking seats. The main method initializes objects and gets user input for train details, passenger details and reservation date before displaying the booked seats and reservation details.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

JAVA

ASSIGNMENT

Bachelor in Technology
(Information Technology)

SCHOOL OF CSE (LPU)


PHAGWARA

Name: Raghu Nandan Reddy Chamakura


Reg no: 11802833
Roll no : A33
Section: K18GX

LOVELY PROFESSIONAL UNIVERSITY


Phagwara (Punjab)
RAILWAY RESERVATION SYSTEM:
INPUT:
import java.util.*;
import java.io.*;
class railwayreservation extends date
{
int row,col;
public static void main(String[]args) throws IOException
{
Calendar c=Calendar.getInstance();
BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
railway ob=new railway();
date ob2=new date();
railwayreservation ob3=new railwayreservation();
for(;;)
{
ob2.displ();
ob.input();

railrev ob1=new railrev();


System.out.println("SEE THE VACANT POSITION AND THEN BOOK THE BERTH");
ob1.disp();
for (int i=0;i<ob.k;i++)
{
System.out.println("\nEnter ROW NO.OF BERTH:- ");
ob3.row=Integer.parseInt(r.readLine());
System.out.println("AND COLUMN NO. OF BERTH.:-");
ob3.col=Integer.parseInt(r.readLine());
System.out.println("********************Seats Reserved="+(i+1));
ob1.check(ob3.row,ob3.col);
}
System.out.println("\f");
System.out.println("________________________________________________
_________________");
System.out.println("NAME "+" "+" AGE "+" "+" GENDER");
for(int i=0;i<ob.k;i++)
{
System.out.println(ob.name[i]+" "+ob.age[i]+" "+ob.gen[i]+" ");
}

System.out.println("________________________________________________
_________________");
System.out.println("Train name: "+ ob.train);

System.out.println("Date of journey :"+ ob2.dd+"/"+ob2.mm+"/"+ob2.yy);


System.out.println("Departure from:"+ob.ss);
System.out.println("Destination :"+ob.ds);
System.out.println("Coach no."+ob.code);
System.out.println("================================================
=================");
System.out.println("Today is:-
"+c.get(Calendar.DATE)+"/"+(c.get(Calendar.MONTH)+1)+"/"+c.get(Calendar.Y
EAR));

System.out.println(" HAVE A HAPPY JOURNEY ");


System.out.println("________________________________________________
_________________");
System.out.println("Do you want to continue(y/n)?");
String ch=(r.readLine());
if(ch.equalsIgnoreCase("n"))
break;
else
ob1.disp();
}
}

class railrev extends railway


{
int b[][]=new int[10][5];
public railrev()
{
for(int r=0;r<10;r++)
{
for(int c=0;c<5;c++)
{
b[r][c]=0;
}
}
}

public void disp()


{
System.out.println("*********************~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~**************");
for(int r=0;r<10;r++)
{
for(int c=0;c<5;c++)
{
System.out.print(" "+b[r][c]+" ");
}
System.out.println();
}
}
//enter row and column no. of seat
//you want to reserve.
public void check(int r,int c)
{
boolean flag=false;
r=r-1;
c=c-1;
if(r<0||r>=10||c<0||c>=5)
{
System.out.println("Sorry........................There are only 10 rows and 5
columns");

}
else if(b[r][c]==0)
{

b[r][c]=1;
System.out.println(" Requested Confirmed......Wish you a Well Journey ");
disp();

}
else if(b[r][c]==1)
{
for(int j=0;j<5;j++)
{
if(b[r][j]==0)
{
b[r][j]=1;
System.out.println("You have been given an alternative seat. Your seat number
is at row= "+(r+1)+" and column= "+(j+1));
flag=true;
break;
}
}
if(flag==false) System.out.println("Sorry no seat is vacant in this row please
select another row");

disp();

}
}
}

class railway
{
String name[]=new String[6];
String age[]=new String[6];
String gen[]=new String[6];
int k;
String train;
String dj,ds,ss,code;

public void input()throws IOException


{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter train name :-");
train=br.readLine();
System.out.println("Enter coach no.:-");
code=br.readLine();
System.out.println("Enter No. of Persons Travelling:-");
Scanner s=new Scanner(System.in);
k=s.nextInt();
System.out.println("Enter person’s name:-");
for(int i=0;i<k;i++)
{
System.out.print("person name: "+(i+1)+")");
name[i]=br.readLine();
}
System.out.println("Enter Age:-");
for(int i=0;i<k;i++)
{
System.out.print("age: "+(i+1)+")");
age[i]=br.readLine();
}
System.out.println("Enter Gender:-");
for(int i=0;i<k;i++)
{
System.out.print("person: "+(i+1)+")");
gen[i]=br.readLine();

}
System.out.println("Enter start station:-");
ss=br.readLine();

System.out.println("Enter destination station:-");


ds=br.readLine();
//System.out.println("Enter date of journey:-");
//dj=br.readLine();

}
}

class date
{
int yy,mm,dd;

boolean f;
public void displ()throws IOException
{
Calendar c=Calendar.getInstance();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
for(;;)
{
System.out.println("Enter year:-");
yy=Integer.parseInt(br.readLine());
System.out.println("Enter month:-");
mm=Integer.parseInt(br.readLine());
System.out.println("Enter day:-");
dd=Integer.parseInt(br.readLine());
System.out.println("Today is:-
"+c.get(Calendar.DATE)+"/"+(c.get(Calendar.MONTH)+1)+"/"+c.get(Calendar.Y
EAR));

int mmst=c.get(Calendar.MONTH)+1;
int md=mm-mmst;
int ddst=c.get(Calendar.DATE);

int ddd=(dd-ddst)+md*30;

System.out.println("differ date="+ddd);
System.out.println("requested date is:-"+dd+"/"+mm+"/"+yy);

if(ddd>=60||ddd<1)
{
System.out.println("Not possible before 60 days or before current date: Re-
Enter new date");

}
else{
System.out.println("VALID DATE...NOW CHECK THE VACANT BERTH");
break;
}
}
}
}
OUTPUT:

You might also like