private static void displayTicket(int timingChoice) throws Exception { // System.out.println("Transaction ID: " + customer.getTransactionId()); // generate the transaction Id here String transactionId = ""; transactionId += (String) customer.getName().substring(0, 3).toUpperCase(); DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmm"); Calendar calendar = Calendar.getInstance(); transactionId += dateFormat.format(calendar.getTime()); String bookingHistory = ""; bookingHistory += movieChosen.getTitle() + ", TransactionId:" + transactionId; customer.addToBookedMovie(bookingHistory); System.out.println("TransactionId: " + transactionId); System.out.println("Your seat: " + customer.getSeat()); System.out.println("choice date: " + choiceDate); System.out.println( "Showing cinema: " + movieChosen .getAvailableMovieDateList() .get(choiceDate - 1) .getCinema() .getCinemaName()); System.out.println("Showing time: " + movieScheduleList.get(timingChoice - 1).getTime()); System.out.println("\n"); }
public static void main(String[] args) { boolean carryOn = true; try { while (carryOn) { int option = requestInput(MAIN_MENU); System.out.flush(); switch (option) { case 1: listMovies(0); break; case 2: listMovies(1); break; case 3: ArrayList<String> searchResult = new ArrayList<String>(); String searchMovie = ""; System.out.println("Enter movie title: "); sc.nextLine(); searchMovie = sc.nextLine(); System.out.flush(); for (int i = 0; i < cineplexList.size(); i++) { searchResult = searchCineplex(searchMovie, cineplexList.get(i)); if (searchResult.size() == 0) { System.out.println( cineplexList.get(i).getCineplexName() + ": No movie to show. \n"); } else { for (int j = 0; j < searchResult.size(); j++) { System.out.println(searchResult.get(j)); } } System.out.println(""); } break; case 4: int cineplexChoice = 0; requestInput(BOOKING_MAIN_INTERFACE); if (customer.confirmCustomerInfo()) cineplexChoice = requestInput(CINEPLEX_INTERFACE); else { System.out.println("Cancelled"); break; } movieListForSpecificCineplex = cineplexList.get(cineplexChoice - 1).getMovieListAvailable(); int movieChoice = requestInput(MOVIE_INTERFACE_FOR_SELECTED_CINEPLEX); movieChosen = movieListForSpecificCineplex.get(movieChoice - 1); movieScheduleList = movieChosen.getAvailableMovieDateList(); if (movieScheduleList.size() > 0) { int timingChoice = requestInput(SELECT_TIMING_INTERFACE); choiceDate = timingChoice; int ageGroup = requestInput(SELECT_AGE_GROUP_INTERFACE); double ticketPrice = movieChosen.getPrice(ageGroup, choosenDate); requestInput(SELECT_SEAT); movieChosen.notificationMessage(); System.out.println( "Ticket price is SGD " + ticketPrice + "." + " Proceed to payment? (y / n)"); String confirmation = sc.next(); if (confirmation.equals("y") || confirmation.equals("Y")) try { displayTicket(timingChoice); } catch (Exception e) { e.printStackTrace(); } userDatabase.writeToDatabase("CineplexDatabase.dat", cineplexList); customerDatabase.writeToDatabase("CustomerDatabase.dat", customerList); } else { System.out.println("No schedule movie"); } break; case 5: System.out.println("Select a movie to rate: "); requestInput(MOVIE_INTERFACE); break; case 6: requestInput(CHECK_MOVIE_INTERFACE); break; case 7: System.out.println("Quitting"); System.exit(0); } } } catch (Exception e) { e.printStackTrace(); System.out.println("Your input is invalid that make this program undergo exception fault"); System.out.println("1) Restart Program"); System.out.println("2) Quit"); sc.nextLine(); int option = sc.nextInt(); if (option == 1) { UserApplication.main(args); } else { System.out.println("Quit"); return; } } }
private static int requestInput(int userInterface) { switch (userInterface) { case MAIN_MENU: System.out.println( "Choose one option:\n" + "1) List the movies available\n" + "2) List the movies with details\n" + "3) Search for movies\n" + "4) Book ticket\n" + "5) Rate,Review and see the top movie\n" + "6) View your booking\n" + "7) Exit\n"); // input check while (true) { if (sc.hasNextInt()) { int choice = sc.nextInt(); if (choice > 0 && choice <= 7) return choice; else continue; } sc.nextLine(); System.out.println("Invalid Option, choose again: "); } case CINEPLEX_INTERFACE: System.out.println("Choose cineplex:"); for (int i = 0; i < cineplexList.size(); i++) { System.out.printf("%d) ", i + 1); System.out.println(cineplexList.get(i).getCineplexName()); } // input check while (true) { if (sc.hasNextInt()) { int choice = sc.nextInt(); if (choice > 0 && choice <= cineplexList.size() + 1) return choice; else continue; } sc.nextLine(); System.out.println("Invalid Option, choose again: "); } case MOVIE_INTERFACE_FOR_SELECTED_CINEPLEX: System.out.println("Choose movie:"); for (int i = 0; i < movieListForSpecificCineplex.size(); i++) { System.out.printf("%d) ", i + 1); System.out.println(movieListForSpecificCineplex.get(i).getTitle()); } // input check while (true) { if (sc.hasNextInt()) { int choice = sc.nextInt(); if (choice > 0 && choice <= movieListForSpecificCineplex.size() + 1) return choice; else continue; } sc.nextLine(); System.out.println("Invalid Option, choose again: "); } case MOVIE_INTERFACE: /*System.out.println("Choose movie:"); for (int i = 0; i < movieListForAllCineplex.size(); i++){ System.out.printf("%d) ", i + 1); System.out.println(movieListForAllCineplex.get(i).getTitle()); } if (sc.hasNextInt()){ int choice = sc.nextInt(); while (choice >= movieListForAllCineplex.size() + 1){ System.out.println("Invalid Option, choose again: "); choice = sc.nextInt(); } return choice; } */ // print all the movie from ratedmovie System.out.println("1) Top 5 Movie based on Rating"); System.out.println("2) Top 5 movie based on Ticket Sales"); System.out.println("3) Rate the movie"); System.out.println("4) Write your review here"); System.out.println("5) See the review of your favorite movie"); int choiceOption = sc.nextInt(); switch (choiceOption) { case 1: ratedMovie.printTopFiveMovieBasedOnRating(); break; case 2: ratedMovie.printTopFiveMovieBasedOnTicket(); break; case 3: ratedMovie.printTopFiveMovieBasedOnRating(); System.out.println("which movie you want to rate"); int movieRatedOption = sc.nextInt(); while (true) { System.out.println("insert your rating here(1-5)"); double rating = sc.nextDouble(); if (rating > 5 || rating < 0) { System.out.println("sorry please put the acceptable range\n"); continue; } ratedMovie.updateMovieRating(movieRatedOption - 1, rating); break; } break; case 4: ratedMovie.printNormalMovieList(); System.out.println("Which movie you want to review"); int optionReview = sc.nextInt(); String movieHasRated = ratedMovie.getRatedMovie().get(optionReview - 1).getTitle(); sc.nextLine(); System.out.println("Insert your name please"); String bufferName = sc.nextLine(); System.out.println("Insert your review here"); String reviewIns = "Review: \n"; String reviewInserted = sc.nextLine(); reviewIns += reviewInserted; System.out.println(""); ratedMovie.updateMovieReview(bufferName, reviewIns, optionReview - 1); break; case 5: ratedMovie.printNormalMovieList(); System.out.println("which movie you want to see the review"); int optionReview1 = sc.nextInt(); ratedMovie.printReview(optionReview1 - 1); break; } ratedMovieDatabase.writeToDatabase("RatedMovie.dat", readMovie); System.out.println(""); return 0; case BOOKING_MAIN_INTERFACE: String customerEmailAdd; int customerPhoneNumber; System.out.println("Please enter your name: "); sc.nextLine(); String customerName = sc.nextLine(); System.out.println("Please enter your phone number: "); do { customerPhoneNumber = sc.nextInt(); if (customerPhoneNumber / 10000000 == 8 || customerPhoneNumber / 10000000 == 9) break; else System.out.println("Invalid phone number, enter again: "); ; } while (true); System.out.println("Please enter your e-mail address: "); do { customerEmailAdd = sc.next(); if (validateEmailAdd(customerEmailAdd) == false) System.out.println("Invalid email address, enter again: "); else break; } while (true); // need to check whether there has a people with the same name or not boolean pass = true; for (int i = 0; i < customerList.size(); i++) { customer = (Customer) customerList.get(i); if (customer.getEmailAdd().equals(customerEmailAdd)) { System.out.println("\nyour account has been in database"); pass = false; break; } } if (pass) { customer = new Customer(customerName, customerPhoneNumber, customerEmailAdd); customerList.add(customer); } return 0; case RATING_INTERFACE: System.out.println("Select movie from list below to rate: "); listMovies(0); System.out.print("Your selection: "); return 0; case SELECT_TIMING_INTERFACE: System.out.println("Choose timing:"); for (int i = 0; i < movieScheduleList.size(); i++) { System.out.printf("%d) ", i + 1); System.out.println(movieScheduleList.get(i).getTime()); } // input check while (true) { if (sc.hasNextInt()) { int choice = sc.nextInt(); if (choice > 0 && choice <= movieScheduleList.size() + 1) { choosenDate = movieScheduleList.get(choice - 1); return choice; } else continue; } sc.nextLine(); System.out.println("Invalid Option, choose again: "); } case SELECT_AGE_GROUP_INTERFACE: System.out.println("Select your age group:"); System.out.println( "1) Child (12 and below)" + "\n2) Adult (13-64)" + "\n3) Senior Citizen (65 and above)"); // input check while (true) { if (sc.hasNextInt()) { int choice = sc.nextInt(); if (choice > 0 && choice <= 4) return choice; else continue; } sc.nextLine(); System.out.println("Invalid Option, choose again: "); } case SELECT_SEAT: Cinema showingCinema = movieChosen.getAvailableMovieDateList().get(choiceDate - 1).getCinema(); boolean success = true; System.out.println(showingCinema.getSeatArrangement()); System.out.println("Select seat from cinema layout above: "); System.out.print("Row (A - J): "); String row = sc.next(); System.out.print("Column (1 - 10): "); int column = sc.nextInt(); while (!showingCinema.requestSeat(row, column)) { System.out.println("Seat taken, please select again"); System.out.print("(To cancel, enter 'z') Row (A - J): "); row = sc.next(); if (row.equals("z")) { success = false; break; } System.out.print("Column (1 - 10): "); column = sc.nextInt(); } if (success == true) { System.out.println("Successfully booked! movie name: " + movieChosen.getTitle()); customer.assignSeat(row + Integer.toString(column)); ratedMovie.updateMovieTicket(movieChosen.getTitle()); } else { System.out.println("Cancelled"); } return 0; case CHECK_MOVIE_INTERFACE: System.out.println("Enter your email address: "); do { customerEmailAdd = sc.next(); if (validateEmailAdd(customerEmailAdd) == false) System.out.println("Invalid email address, enter again: "); else break; } while (true); Customer currentCustomer = null; for (int i = 0; i < customerList.size(); i++) { if (((Customer) customerList.get(i)).getEmailAdd().equals(customerEmailAdd)) { currentCustomer = (Customer) customerList.get(i); break; } } if (currentCustomer != null) { ArrayList<String> temp = currentCustomer.getBookedMovieList(); String currentTransactionId = currentCustomer.getTransactionId(); printBookedMovie(temp, currentTransactionId); } else { System.out.println("Sorry database do not save your email, have you ordered yet?\n"); } return 0; default: return 0; } }