public cn.bran.japid.template.RenderResult render(String blogTitle, List<Post> allPost) { this.blogTitle = blogTitle; this.allPost = allPost; long t = -1; try { super.layout(); } catch (RuntimeException e) { super.handleException(e); } // line 3 return new cn.bran.japid.template.RenderResultPartial( getHeaders(), getOut(), t, actionRunners, sourceTemplate); }
/** Check seats and book ticket. */ private void checkSeatsAndBookTicket() { Layout layout; System.out.println(LINE_SPACING); movieUser.printMovieList(); boolean done = false; int bookingId = 0; while (!done) { System.out.print("Enter the id of the movie you want to see : "); try { bookingId = Integer.parseInt(sc.nextLine()); } catch (NumberFormatException e) { System.out.println("Please enter a valid number!"); continue; } done = true; } Movie m = movieUser.getMovieByID(bookingId); Date time = null; if (m != null) { bookingController.setMovie(m); ShowTimes showTimes = showTimesController.getShowTimes(bookingId); if (showTimes == null || showTimes.getTime().isEmpty()) { System.out.println( "There is no available showtimes for this movie. Please choose another movie"); return; } System.out.println(LINE_SPACING); showTimesController.printShowTimesByMovie(bookingId); System.out.print("Choose the showtimes: "); int choice = 0; try { choice = Integer.parseInt(sc.nextLine()); } catch (Exception e) { System.out.println("Please enter a valid number!"); return; } while (true) { if (choice <= showTimes.getTime().size()) { time = showTimes.getTime().get(choice - 1); Cinema cinema = showTimes.getCinema().get(choice - 1); bookingController.setCinema(cinema); String transactionID = cinema.getCode(); bookingController.setTransactionID(transactionID); layout = cinema.getLayOut(); System.out.println(LINE_SPACING); layout.viewLayOut(); break; } else { System.out.println("Please choose again: "); continue; } } System.out.print("Please enter number of seats you want to choose: "); int ticketNumber = 0; done = false; while (!done) { try { ticketNumber = Integer.parseInt(sc.nextLine()); } catch (NumberFormatException e) { System.out.println("Please enter a valid number!"); continue; } done = true; } bookingController.setTicketNumber(ticketNumber); for (int i = 0; i < ticketNumber; i++) { System.out.println("Please enter your choice of seat:"); while (true) { int row; while (true) { System.out.print("Enter row: "); try { row = Integer.parseInt(sc.nextLine()); } catch (NumberFormatException e) { System.out.println("Please enter a valid number!"); continue; } if (row <= layout.getRow()) break; System.out.println("Enter row again."); } int column; while (true) { System.out.print("Enter column: "); try { column = Integer.parseInt(sc.nextLine()); } catch (NumberFormatException e) { System.out.println("Please enter a valid number!"); continue; } if (column <= layout.getCol()) break; System.out.println("Enter column again."); } boolean isChosen = bookingController.seatSelection( showTimesController .getShowTimes(bookingId) .getCinema() .get(choice - 1) .getLayOut(), row, column); if (isChosen) { System.out.println("Choose sucessfully!"); showTimesController.save(); break; } else { System.out.println("Seat is not available! Please choose again"); continue; } } } } else { System.out.println("Movie not found. Please try again!"); } System.out.println(LINE_SPACING); int basePrice = ticketController.getBasePrice(); bookingController.setBasePrice(basePrice); String name, mobileNumber, emailAddress; int age = 0; System.out.print("Enter your name: "); name = sc.nextLine(); System.out.print("Enter your mobile number: "); mobileNumber = sc.nextLine(); System.out.print("Enter your email address: "); emailAddress = sc.nextLine(); done = false; while (!done) { System.out.print("Enter your age: "); try { age = Integer.parseInt(sc.nextLine()); } catch (Exception e) { System.out.println("Please enter a valid number!"); continue; } done = true; } bookingController.setMovieGoer(name, mobileNumber, emailAddress, age); bookingController.generateTransactionID(); System.out.println("Ticket booked! Below is your receipt: "); bookingController.bookTicket(time); bookingController.saveBooking(); movieUser.save(); time = null; // prevent 2 users can book 1 seat. }