forked from SAG786/Cinema-Booking-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cinema.java
223 lines (214 loc) · 6.02 KB
/
Cinema.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
import java.util.*;
import java.io.*;
import java.util.regex.*;
class Info
{
String name,mobno,email;
int gender;// 0 for woman, 1 for man
}
public class Cinema
{
public static boolean isValidMob(String s)
{
Pattern p = Pattern.compile("(0/91)?[7-9][0-9]{9}");
Matcher m = p.matcher(s);
return (m.find() && m.group().equals(s));
}
public static void main(String []args) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Scanner sc=new Scanner(System.in);
Connection con=DriverManager.getConnection("jdbc:odbc:Cinema");
PreparedStatement ps=con.prepareStatement("insert into Ticket values(?,?,?,?)");
int opt,num,x,y;
String name,mobno,email;
int gender;
int n=5;
int seat1[][]=new int[n][n];
int seat2[][]=new int[n][n];
int seat3[][]=new int[n][n];
int ref1[][]=new int[n][n];
int ref2[][]=new int[n][n];
int ref3[][]=new int[n][n];
ArrayList<Info>Andhadhun=new ArrayList<Info>();
ArrayList<Info>Deadpool=new ArrayList<Info>();
ArrayList<Info>Bazaar=new ArrayList<Info>();
int pos_a=0,pos_c=0,pos_b=0,mov;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
seat1[i][j]=seat2[i][j]=seat3[i][j]=0;
}
while(true)
{
System.out.print("\n\t\tCinema Booking System\n\nEnter which movie do you want to see:\n1.Andhadhun\n2.Deadpool\n3.Bazaar\n4.Exit\nOption:");
mov=sc.nextInt();
if(mov<0&&mov>=4)
break;
while(true)
{
System.out.print("\n\n1.Buy/Book a ticket\n2.View the Cinema Hall\n3.Count\n4.View Ticket Details\n5.Exit\n\nOption:");
opt=sc.nextInt();
if(opt<1||opt>4)
break;
switch(opt)
{
case 1:
System.out.print("\nEnter how many tickets do you want to buy:");
num=sc.nextInt();
for(int i=0;i<num;i++)
{
Info obj=new Info();
while(true)
{
System.out.println("Enter position of seats to book :");
x=sc.nextInt();
y=sc.nextInt();
if((x<0&&x>=n)||(y<0&&y>=n))
{
System.out.println("Invalid Position");
continue;
}
if((mov==1&&seat1[x][y]==1)||(mov==2&&seat2[x][y]==1)||(mov==3&&seat3[x][y]==1))
{
System.out.println("This seat is already filled\nTry again");
continue;
}
if(mov==1)
seat1[x][y]=1;
else if(mov==2)
seat2[x][y]=1;
else
seat3[x][y]=1;
break;
}
System.out.println("Enter Following details:");
System.out.print("Name:");
name=sc.next();
while(true)
{
System.out.print("Mobile Number:");
mobno=sc.next();
if(isValidMob(mobno))
break;
System.out.println("Invalid..please type again");
}
System.out.print("Gender(0 for female, 1 for male):");
gender=sc.nextInt();
System.out.print("Enter email-address:");
email=sc.next();
obj.name=name;
obj.mobno=mobno;
obj.email=email;
obj.gender=gender;
if(mov==1)
{
Andhadhun.add(obj);
ref1[x][y]=pos_a;
pos_a++;
}
else if(mov==2)
{
Deadpool.add(obj);
ref2[x][y]=pos_b;
pos_b++;
}
else
{
Bazaar.add(obj);
ref3[x][y]=pos_c;
pos_c++;
}
}
break;
case 2:
/* System.out.println("-----------------------------------------------------");
System.out.println("--------------------Screen---------------------------");
System.out.println("-----------------------------------------------------");*/
System.out.println(" ---------------------");
System.out.println(" -------SCREEN--------");
System.out.println(" ---------------------");
if(mov==1)
{
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(j==0)
System.out.print(" | ");
System.out.print(seat1[i][j]+" | ");
if(j==n-1)
System.out.println();
}
System.out.println(" ---------------------");
}
}
else if(mov==2)
{
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(j==0)
System.out.print(" | ");
System.out.print(seat2[i][j]+" | ");
if(j==n-1)
System.out.println();
}
System.out.println(" ---------------------");
}
}
else
{
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(j==0)
System.out.print(" | ");
System.out.print(seat3[i][j]+" | ");
if(j==n-1)
System.out.println();
}
System.out.println(" ---------------------");
}
}
break;
case 3:
if(mov==1)
System.out.println("Out Off 25 tickets only "+ (25-pos_a) +" tickets are remaining");
else if(mov==2)
System.out.println("Out Off 25 tickets only "+ (25-pos_b) +" tickets are remaining");
else
System.out.println("Out Off 25 tickets only "+ (25-pos_c) +" tickets are remaining");
break;
case 4:
while(true)
{
System.out.print("Enter the (Position):");
x=sc.nextInt();
y=sc.nextInt();
if((mov==1&&seat1[x][y]!=0)||(mov==2&&seat2[x][y]!=0)||(mov==3&&seat3[x][y]!=0))
{
break;
}
System.out.println("Seat is empty here..please try again...");
}
Info data=new Info();
if(mov==1)
data=Andhadhun.get(ref1[x][y]);
else if(mov==2)
data=Deadpool.get(ref2[x][y]);
else
data=Bazaar.get(ref3[x][y]);
System.out.println("\n\t\tDetails\nName:"+data.name+"\nMobile Number:"+data.mobno+"\nEmail address:"+data.email);
if(data.gender==0)
System.out.println("Gender:female\n");
else
System.out.println("Gender:male\n");
break;
}
}
}
}
}