You are on page 1of 5

package com.jsp.

BookMyShow;

public class Test {

public static void main(String[] args) {


BookMyShow show = BookMyShow.getInstance();
show.open();
}
}

public class Screen {


final int totalSeats=100;
int reservedSeats;
int avaliableSeats=100;

public class Theatre {


protected static Screen s1 = new Screen();
protected static Screen s2 = new Screen();
}

public class BookingApp extends Theatre{

Scanner scan = new Scanner(System.in);

public int bookingPage(Screen s) {


System.out.println("Enter the no of seats to reserve: ");
int seats = scan.nextInt();
if (seats > s.avaliableSeats) {
System.out.println(
"Sorry sir....There are only " + s.avaliableSeats + "
seats\n" + "So booking cant be done");

System.out.println(
"Choose the option from below : \n" + "1. To revisit
the Booking page \n" + "2. To return back");
int option = scan.nextInt();
for (;;) {
switch (option) {
case 1:
bookingPage(s);
break;
case 2:
return 0;
default:
System.out.println("Enter the correct input");
}
}
} else {
s.avaliableSeats=s.avaliableSeats-seats;
s.reservedSeats+=seats;
return seats;
}

}
}

public class BookMyShow extends BookingApp {


static BookMyShow b=null;
Scanner scan = new Scanner(System.in);
private BookMyShow() {

}
public static BookMyShow getInstance() {
if(b==null)b=new BookMyShow();
return b;
}

public void open() {


System.out
.println("Choose the option from below :\n"
+ "1. To visit the theatre page\n"
+ "2. To close the app");
int option = scan.nextInt();
switch (option) {
case 1:
theatrePage();
break;
case 2:
return;
default:
System.out.println("Enter the correct input");
}
}

public void theatrePage() {


System.out.println("There are 2 screens in the theatre choose one : \n"
+ "1. TO visit Screen-1\n"
+ "2. To visit Screen-2\n"
+ "3. To return back");
int option = scan.nextInt();
switch (option) {
case 1:
ScreenPage(s1);
break;
case 2:
ScreenPage(s2);
break;
case 3:
return;
default:
System.out.println("Do you want to Continue or Exist?\n"
+ "1. Continue\n"
+ "2. Exist");
option= scan.nextInt();
switch(option) {
case 1:
theatrePage();
break;
case 2:
return;
default:
System.out.println("I have already given a chance to
correct yourself......But u again entering the wrong key....So GoodBye...");
}
}
}

public void ScreenPage(Screen s) {


System.out.println("Total No of seats in the screen =" + s.totalSeats);
System.out.println("Available seats =" +
s.avaliableSeats);
System.out.println("Reserved seats =" +
s.reservedSeats);
System.out.println("Ticket price =122");

System.out.println("Coose the option from below: \n"


+ "1. To book the Tickets\n"
+ "2. To return to Theatre page\n" +
"3. To close the app");
int option = scan.nextInt();
switch (option) {
case 1:
bookTickets(s);
break;
case 2:
theatrePage();
break;
case 3:
return;
default:
System.out.println("You have entered the wrong input.....So we
are returning back");
}
}

public void bookTickets(Screen s) {


int seats = bookingPage(s);
if (seats > 0) {
System.out.println();
double amount = 122 * seats;
amount = (28.0 * amount / 100.0) + amount; // By adding the GST
and CGST
System.out.println("Total Amount = " + amount + "
Rs/-\n");
System.out.println("Choose the option from below :\n"
+ "1. If u want to continue the payment\
n"
+ "2. To return back");
int option = scan.nextInt();
switch (option) {
case 1:
paymentDetails(seats, amount, s);
break;
case 2:
return;
default:
System.out.println("Enter the correct input");
}
}
return;
}

public void paymentDetails(int seats, double amount, Screen s) {


System.out.print("Enter the name : ");
String name = scan.next();
System.out.print("Enter Phone Number : ");
String phoneNo = scan.next();
System.out.print("Enter E Mail-ID : ");
String email = scan.next();
int count = 0;
for (; true;) {
if (count > 5) {
System.out.println("The payment limit has been exceeded");
break;
}
System.out.print("Enter the Amount to pay : ");
double payment = scan.nextDouble();
if (payment < amount) {
System.out.println("The amount you need to pay is " +
amount + " Rs/- \n"
+ "You have paid " + payment+
" Rs/- \n"
+ "Remainig amount " +
(amount - payment) + " also need to pay to confirm the seats booking");

inner: for (;;) { //Mentioned the name as inner for


the loop
System.out.println(
"Choose the option from below :\n"
+ "1. To retry the payment\n"
+ "2. To return back");
int option = scan.nextInt();
switch (option) {
case 1:
break inner; // breaking the loop
case 2:
return;
default:
System.out.println("Enter the correct input");
}
}

} else {
System.out.println("The payment has been done successfully
");
billGenerator(name, phoneNo, email, seats, s);
break;
}
count++;
}
}

public void billGenerator(String name, String phoneNo, String email, int


seats, Screen s) {
System.out.println("************************");
System.out.println("Qyantitiy" + " - " + seats);
if (s == s1)
System.out.println("Screen - S1");
else
System.out.println("Screen - S2");
double amount = 122 * seats;
System.out.println("Amount - " + amount+"\n");
System.out.println("Adding 14% GST on " + amount);
System.out.println("Adding 14% CGST on " + amount+"\n");
System.out.println("Final Amount - " + ((28.0 * amount / 100.0)
+ amount));
System.out.println("**************************");

for (;;) {
System.out.println("Choose the option from below: \n" +
"1. To visit the page again\n" +
"2. To return ");
int option = scan.nextInt();
switch (option) {
case 1:
open();
break;
case 2:
return;
default:
System.out.println("Enter the correct input");
}
}
}

You might also like