Java Project Code: Cinema Ticket booking system : Create a Java Application to book a ticket in a Cinema hall.
Cinema Ticket booking system :
Create a Java Application to book a ticket in a Cinema hall. Create appropriate class to represent a Ticket and User. Use 2-D arrays to store the seats of the hall. Definition of done:
The System should ask user to enter Username and Password. X, The system should give option of different available movies. After selecting a movie give option of different seats available.
A user should be able to book or cancel a ticket.
Store the information in text file.
Code for this Project
import java.util.Scanner;
import java.io.* ;
class Bookticket
{
static String seating[][] = { { "A1", "A2","A3","A4" }, { "B1", "B2","B3","B4" },{"C1","C2","C3","C4" },{"D1","D2","D3","D4"}};
static int I,J;
static String z;
public void PrintAvaliable()
{
try
{
File TICKET = new File("TICKET.txt");
FileWriter FW = new FileWriter(TICKET);
BufferedWriter BW = new BufferedWriter(FW);
System.out.println("Now Avaliable Seats are");
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
if(seating[i][j].equals("X")==false)
{
BW.write(seating[i][j]+" ");
}
}
BW.write("\n");
}
FileReader FR = new FileReader(TICKET);
BufferedReader BR = new BufferedReader(FR);
String Line ;
while(( Line = BR.readLine())!=null)
{
System.out.println(Line);
}
BW.close();
System.out.println("File saved successfully");
} catch(Exception e){
System.out.println(e);
}
}
public void bookfunction(String a) throws Exception
{
int Con=16;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
if((seating[i][j].equals(a)==true))
{
I=i;
J=j;
z=seating[i][j]; seating[i][j]="X";
}
else
{
Con--;
}
}
}
if(Con!=0){System.out.println("Seat Booked");}else{throw new Exception("");
}
}
public void canc()
{
seating[I][J]=z;
System.out.println("Booking Cancelled");
}
}
public class HelloWorld1 {
public static void main(String[] args) {
int b=3;
String movie;
System.out.println("Hello, Welcome to BookMyShow");
System.out.println("Please Enter your Name ");
Scanner sc= new Scanner(System.in);
String str= sc.nextLine();
System.out.println("Please Enter your Password ");
String str1= sc.nextLine();
System.out.println(str);
if ((str.equals("Pass1")==true) &&(str1.equals("Pass2")==true))
{
System.out.println(" THANKS FOR LOGIN");
System.out.println("MOVIES are DHOL , WELCOME, RADHE , DHAMAAL");
System.out.println("ENTER MOVIE NAME");
Scanner mo=new Scanner(System.in);
movie=mo.nextLine();
Bookticket bt= new Bookticket();
bt.PrintAvaliable();
System.out.println("KINDLY SELECT A SEAT");
String str2= sc.nextLine();
try{
bt.bookfunction(str2);
bt.PrintAvaliable();
}
catch(Exception e)
{
System.out.println("Wrong Seat");
System.exit(0);
}
System.out.println("Please Enter C for Cancel and E for Exit");
String str3= sc.nextLine();
if(str3.equals("C")==true)
{
bt.canc(); bt.PrintAvaliable();
}
else if(str3.equals("E")==true)
{
System.exit(0);
}
}
else
{
System.out.println("Authentication fail");
System.exit(0);
}
}
}
Comments
Post a Comment