/** Adds the review. */ private void addReview() { int id = 0; System.out.println(LINE_SPACING); String detail = null; int rating = 0; System.out.println("The movie list: "); movieUser.printMovieList(); boolean done = false; while (!done) { System.out.print("Enter the id of the movie you want to review: "); try { id = Integer.parseInt(sc.nextLine()); } catch (NumberFormatException e) { System.out.println("Please enter a valid number!"); continue; } System.out.println(LINE_SPACING); System.out.print("Enter your review: "); detail = sc.nextLine(); while (true) { System.out.print("Rate the movie(from 1 to 5): "); try { rating = Integer.parseInt(sc.nextLine()); } catch (NumberFormatException e) { System.out.println("Please enter a valid number!"); continue; } break; } System.out.println("Thank you for your review!"); done = true; } movieUser.updateReview(id, detail, rating); movieUser.save(); }
/** Search movie. */ private void searchMovie() { String movieName; System.out.println(LINE_SPACING); System.out.print("Enter the name of the movie you want to search for: "); movieName = sc.nextLine(); System.out.println(LINE_SPACING); boolean isSearched = movieUser.searchMovie(movieName); if (!isSearched) { System.out.println("Movie not found. Please try again!"); } }
/** Start. */ public void start() { // Show the list of action that users can choose. // To be called by controller. // Controller then take the user input and perform the logic functions. int userChoice; boolean isQuit = false; do { printUserMenu(); try { userChoice = Integer.parseInt(sc.nextLine()); } catch (NumberFormatException e) { System.out.println("Please enter a valid number!"); continue; } switch (userChoice) { case 1: searchMovie(); break; case 2: System.out.println(LINE_SPACING); System.out.println("The movie lists: "); movieUser.printMovieList(); break; case 3: requestMovieDetails(); break; case 4: checkSeatsAndBookTicket(); break; case 5: viewBookingHistory(); break; case 6: addReview(); break; case 7: System.out.println(LINE_SPACING); System.out.println("Here are top 5 movies by ticket sales: "); movieUser.listTopTicketSales(); break; case 8: System.out.println(LINE_SPACING); System.out.println("Here are top 5 movies by rating: "); movieUser.listTopRating(); break; default: isQuit = true; break; } } while (!isQuit); }
/** Request movie details. */ private void requestMovieDetails() { int id = 0; System.out.println(LINE_SPACING); movieUser.printMovieList(); boolean done = false; while (!done) { System.out.print("Enter the id of the movie you want to view details: "); try { id = Integer.parseInt(sc.nextLine()); } catch (NumberFormatException e) { System.out.println("Please enter a valid number!"); continue; } System.out.println(LINE_SPACING); done = true; } boolean isPrinted = movieUser.printMovieDetails(id); if (!isPrinted) { System.out.println("Movie not found. Please try again!"); } }
/** 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. }