-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
393 lines (363 loc) · 16.8 KB
/
Main.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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
class Theatre{
String theatreName;
int balance;
int availableSeats;
int totalSeats;
Movie onShow;
Boolean hasBooked = false;
Theatre(String theatreName, int totalSeats, Movie onShow) {
this.theatreName = theatreName;
this.balance = 0;
this.availableSeats = totalSeats;
this.totalSeats = totalSeats;
this.onShow = onShow;
}
Boolean bookTicket(int ticketCount, int price){
if(availableSeats >= ticketCount){
availableSeats -= ticketCount;
balance += price*ticketCount;
hasBooked = true;
return true;
}
return false;
}
Boolean cancelTicket(int ticketCount, int price){
if(hasBooked != true){
return false;
}
if(ticketCount > totalSeats-availableSeats){
System.out.println("Only "+ (totalSeats-availableSeats) +" tickets have been booked!");
Scanner input = new Scanner(System.in);
System.out.println("1) Cancel remaining seats\n2) Exit");
int choice = input.nextInt();
if(choice == 1){
balance -= refund((totalSeats-availableSeats),price);
availableSeats = totalSeats;
hasBooked = false;
}
else {
hasBooked = true;
return false;
}
}
return true;
}
int refund(int ticketCount, int price){
int refundAmount = ticketCount*price * 50/100;
return refundAmount;
}
}
class Movie{
String title;
int price;
String language;
String certificate;
float duration;
int ratingCount;
float rating;
Movie(String title, String certificate, int price, float duration, String language){
this.title = title;
this.certificate = certificate;
this.price = price;
this.duration = duration;
this.language = language;
}
void getRating(float rating){
ratingCount++;
rating = (this.rating + rating) / 2;
}
}
class Snacks
{
String snacks[]={"PEPSI","COKE","7-UP","BURGER-VEG","BURGER-CHICKEN","COLD COFFEE","POPCORN","CORN","ICE-CREAM","FRENCH-FRIES","CHICKEN POPCORN","NACHOS","VEG-PUFF",
"CHICKEN-PUFF","COFFEE","TEA"};
int price[]={100,100,100,120,180,80,80,60,100,110,130,200,40,50,30,20};
String bill[]={"","","","","","","","","","","","","","","",""};
int quantity,rate,total=0;
String[] Bill(List <Integer> order)
{
int count=0;
Scanner sc=new Scanner(System.in);
for(int i:order)
{
System.out.println("Enter quantity required for "+snacks[i-1]);
quantity=sc.nextInt();
rate=price[i-1]*quantity;
total=total+rate;
bill[count]=snacks[i-1]+" x "+quantity+" :"+rate;
count++;
}
return bill;
}
int amount()
{
return total;
}
}
class Main {
static Movie[] movieArray = new Movie[4];
static int index1 = -1;
static Theatre[] theatreArray = new Theatre[4];
static int index2 = -1;
static String[] snackArray = new String[10];
public static void newMovie(String title, String certificate, int price, float duration, String language){
Movie movie = new Movie(title, certificate, price, duration, language);
movieArray[++index1] = movie;
}
public static void newTheatre(String theatreName, int totalSeats, Movie onShow){
Theatre movie = new Theatre( theatreName, totalSeats, onShow);
theatreArray[++index2] = movie;
}
public static void main(String[] args){
int choice;
int book;
newMovie("Sardar","U/A",200,2.46f,"Tamil");
newMovie("Kantara","U/A",190,2.30f,"Kannada");
newMovie("Black Adam","U/A",190,2.05f,"English");
newMovie("Prince","U",300,2.23f,"Telugu");
newTheatre("PVR Theatres",190,movieArray[0]);
newTheatre("Swami Cinemas",300,movieArray[1]);
newTheatre("Subramani Cinemas",500,movieArray[2]);
newTheatre("Sajee Multiplex" ,200,movieArray[3]);
Scanner input = new Scanner(System.in);
System.out.println("Welcome to Ticket booking service!");
do{
System.out.println("The movies available :\n");
for(int i=0 ; i<4 ; i++) {
System.out.println(i+1+") "+movieArray[i].title);
}
System.out.println("5) Exit");
System.out.println("Enter your choice of movie according to serial number:");
choice = input.nextInt();
switch (choice) {
case 1:
System.out.println(theatreArray[0].theatreName);
System.out.println("Available Seats: " + theatreArray[0].availableSeats);
System.out.println("Ticket Price:" + movieArray[0].price);
System.out.println("Do you want to book ticket?\n" +
"1. Book\n2.Cancel\n3.Exit\n");
book = input.nextInt();
if(book == 1) {
System.out.println("Enter number of tickets:");
int ticketCount = input.nextInt();
if(theatreArray[0].bookTicket(ticketCount,movieArray[0].price)){
System.out.println("Tickets Booked");
Snacks sc=new Snacks();
int index3=1;
List<Integer> snacks_index=new ArrayList<Integer>();
System.out.println("Do you Want Snacks?? 1)Yes 2)No");
int ch=input.nextInt();
if(ch==1) {
for (String i : sc.snacks) {
System.out.println(index3 + ") " + i);
index3++;
}
while(ch!=2)
{
System.out.println("Enter snacks you want");
int snack=input.nextInt();
snacks_index.add(snack);
System.out.println("Do you Want more Snacks?? 1)Yes 2)No");
ch= input.nextInt();
}
String bill[]=sc.Bill(snacks_index);
for(int j=0;j<bill.length;j++) {
if(bill[j] != "") {
System.out.println(bill[j]);
}
}
System.out.println("Total amount for snacks = "+sc.amount());
theatreArray[0].balance += sc.amount();
}
}
else{
System.out.println("Tickets Full");
}
}
else if(book == 2){
System.out.println("Enter number of tickets to cancel:");
int ticketCount = input.nextInt();
if(theatreArray[0].cancelTicket(ticketCount,movieArray[0].price)){
System.out.println("Tickets Cancelled");
}
else{
System.out.println("Couldn't cancel");
}
}
break;
case 2:
System.out.println(theatreArray[1].theatreName);
System.out.println("Available Seats: " + theatreArray[1].availableSeats);
System.out.println("Ticket Price:" + movieArray[1].price);
System.out.println("Do you want to book ticket?\n" +
"1. Book\n2.Cancel\n3.Exit\n");
book = input.nextInt();
if(book == 1) {
System.out.println("Enter number of tickets:");
int ticketCount = input.nextInt();
if(theatreArray[1].bookTicket(ticketCount,movieArray[1].price)){
System.out.println("Tickets Booked");
Snacks sc1=new Snacks();
int index4=1;
List<Integer> snack_index=new ArrayList<Integer>();
System.out.println("Do you Want Snacks?? 1)Yes 2)No");
int ch1=input.nextInt();
if(ch1==1) {
for (String i : sc1.snacks) {
System.out.println(index4 + ") " + i);
index4++;
}
while(ch1!=2)
{
System.out.println("Enter snacks you want");
int snack=input.nextInt();
snack_index.add(snack);
System.out.println("Do you Want more Snacks?? 1)Yes 2)No");
ch1= input.nextInt();
}
String bill[]=sc1.Bill(snack_index);
for(int j=0;j<bill.length;j++) {
if (bill[j] != "") {
System.out.println(bill[j]);
}
}
System.out.println("Total amount for snacks = "+sc1.amount());
theatreArray[1].balance += sc1.amount();
}
}
else{
System.out.println("Tickets Full");
}
}
else if(book == 2){
System.out.println("Enter number of tickets to cancel:");
int ticketCount = input.nextInt();
if(theatreArray[1].cancelTicket(ticketCount,movieArray[1].price)){
System.out.println("Tickets Cancelled");
}
else{
System.out.println("Couldn't cancel");
}
}
break;
case 3:
System.out.println(theatreArray[2].theatreName);
System.out.println("Available Seats: " + theatreArray[2].availableSeats);
System.out.println("Ticket Price:" + movieArray[2].price);
System.out.println("Do you want to book ticket?\n" +
"1. Book\n2.Cancel\n3.Exit\n");
book = input.nextInt();
if(book == 1) {
System.out.println("Enter number of tickets:");
int ticketCount = input.nextInt();
if(theatreArray[2].bookTicket(ticketCount,movieArray[2].price)){
System.out.println("Tickets Booked");
Snacks sc2=new Snacks();
int index5=1;
List<Integer> snack_index2=new ArrayList<Integer>();
System.out.println("Do you Want Snacks?? 1)Yes 2)No");
int ch2=input.nextInt();
if(ch2==1) {
for (String i : sc2.snacks) {
System.out.println(index5 + ") " + i);
index5++;
}
while(ch2!=2)
{
System.out.println("Enter snacks you want");
int snack=input.nextInt();
snack_index2.add(snack);
System.out.println("Do you Want more Snacks?? 1)Yes 2)No");
ch2= input.nextInt();
}
String bill[]=sc2.Bill(snack_index2);
for(int j=0;j<bill.length;j++) {
if (bill[j] != "") {
System.out.println(bill[j]);
}
}
System.out.println("Total amount for snacks = "+sc2.amount());
theatreArray[2].balance += sc2.amount();
}
}
else{
System.out.println("Tickets Full");
}
}
else if(book == 2){
System.out.println("Enter number of tickets to cancel:");
int ticketCount = input.nextInt();
if(theatreArray[2].cancelTicket(ticketCount,movieArray[2].price)){
System.out.println("Tickets Cancelled");
}
else{
System.out.println("Couldn't cancel");
}
}
break;
case 4:
System.out.println(theatreArray[3].theatreName);
System.out.println("Available Seats: " + theatreArray[3].availableSeats);
System.out.println("Ticket Price:" + movieArray[3].price);
System.out.println("Do you want to book ticket?\n" +
"1. Book\n2.Cancel\n3.Exit\n");
book = input.nextInt();
if(book == 1) {
System.out.println("Enter number of tickets:");
int ticketCount = input.nextInt();
if(theatreArray[3].bookTicket(ticketCount,movieArray[3].price)){
System.out.println("Tickets Booked");
Snacks sc3=new Snacks();
int index6=1;
List<Integer> snack_index3=new ArrayList<Integer>();
System.out.println("Do you Want Snacks?? 1)Yes 2)No");
int ch3=input.nextInt();
if(ch3==1) {
for (String i : sc3.snacks) {
System.out.println(index6 + ") " + i);
index6++;
}
while(ch3!=2)
{
System.out.println("Enter snacks you want");
int snack=input.nextInt();
snack_index3.add(snack);
System.out.println("Do you Want more Snacks?? 1)Yes 2)No");
ch3= input.nextInt();
}
String bill[]=sc3.Bill(snack_index3);
for(int j=0;j<bill.length;j++) {
if (bill[j] != "") {
System.out.println(bill[j]);
}
}
System.out.println("Total amount for snacks = " +sc3.amount());
theatreArray[3].balance += sc3.amount();
}
}
else{
System.out.println("Tickets Full");
}
}
else if(book == 2){
System.out.println("Enter number of tickets to cancel:");
int ticketCount = input.nextInt();
if(theatreArray[3].cancelTicket(ticketCount,movieArray[3].price)){
System.out.println("Tickets Cancelled");
}
else{
System.out.println("Couldn't cancel");
}
}
break;
}
System.out.println("Collection:");
for(int i=0; i<4; i++){
System.out.println(theatreArray[i].theatreName+ " - " + theatreArray[i].balance);
}
}while(choice!=5);
}
}