private static ArrayList<String> searchCineplex(String title, Cineplex cineplex) { ArrayList<String> result = new ArrayList<String>(); movieListForSpecificCineplex = cineplex.getMovieList(); for (int i = 0; i < movieListForSpecificCineplex.size(); i++) { Movie curMovie = new Movie(); curMovie = movieListForSpecificCineplex.get(i); if ((curMovie.getTitle().toLowerCase()).equals(title.toLowerCase())) { // processing the status first String status = ""; for (int j = 0; j < curMovie.getArrayListOfMovieDate().size(); j++) { status = curMovie.getArrayListOfMovieDate().get(j).getStatus(); if (status.equals("End of Showing")) { status = "Now Showing"; } } result.add( cineplex.getCineplexName() + ": " + "\n" + curMovie.getTitle() + "\nPrice: " + Double.toString(curMovie.getNormalPrice()) + "\nDuration: " + curMovie.getDuration() + "\nStatus: " + status); } } return result; }
private static int getIndexCinema() { for (int i = 0; i < currentCineplex.getCinemaList().size(); i++) { System.out.printf("%d) %s\n", i + 1, currentCineplex.getCinema(i).getCinemaName()); } System.out.println("please choose which cinema "); int choosenCinema = scan.nextInt(); if (choosenCinema > currentCineplex.getCinemaList().size()) { System.out.println("Sorry your cinema option is invalid"); System.out.println("Please choose again"); return getIndexCinema(); } return choosenCinema; }
public static void removeMovie() { System.out.println("\n------------------------\n"); System.out.println("List movie of " + currentCineplex.getCineplexName() + "............"); for (int i = 0; i < currentCineplex.getMovieList().size(); i++) { System.out.println(i + 1 + ")"); System.out.printf("%s\n", currentCineplex.getMovieList().get(i).printDescription()); } System.out.println("\n------------------------\n"); System.out.println("which movie to be removed"); int optionRemoveMovie = scan.nextInt(); boolean pass = true; String movieDeleted = currentCineplex.getMovieList().get(optionRemoveMovie - 1).getTitle(); currentCineplex.removeMovie(currentCineplex.getMovieList().get(optionRemoveMovie - 1)); // need to remove the movie from rated movie if there has no such movie again in all the // cineplex for (int i = 0; i < cineplexList.size(); i++) { Cineplex cineplex = cineplexList.get(i); ArrayList<Movie> movieRemovedList = cineplex.getMovieList(); for (int j = 0; j < movieRemovedList.size(); j++) { if (movieRemovedList.get(j).getTitle().equals(movieDeleted)) { // means still has this movie in other cineplex so cannot delete it pass = false; break; } } } if (pass) { movieRated.removeMovie(movieDeleted); } System.out.println("changes has been saved to our system \n"); }
private static DateMovie addDateOnNewMovie(String title) { int year, month, day, hour, minute; DateMovie dateMovie; String status; System.out.println("insert the date: "); System.out.print("Year(YYYY): "); year = scan.nextInt(); System.out.print("Month(MM): "); month = scan.nextInt(); System.out.print("Day(DD): "); day = scan.nextInt(); System.out.print("Hour(hh): "); hour = scan.nextInt(); System.out.print("Minute(mm): "); minute = scan.nextInt(); scan.nextLine(); DateMovie checkHolidayDate = new DateMovie(year, month, day); System.out.println("insert the status of the movie on that time"); status = chooseStatusMovie(); System.out.println( "insert the cinema that will be playing " + title + " on " + checkHolidayDate.getYearMonthDay()); int cinemaoption = getIndexCinema(); Cinema cinema = currentCineplex.getCinema(cinemaoption - 1); dateMovie = new DateMovie(cinema, status, year, month, day, hour, minute); return dateMovie; }
private static void listMovies(int cineplex) { if (cineplex == 0) { for (int i = 0; i < cineplexList.size(); i++) { System.out.println(cineplexList.get(i).getCineplexName() + ":"); cineplexList.get(i).listMovie(); System.out.println(); } } else { // first populate all the movie from all cineplex first ArrayList<Movie> movieList = new ArrayList<Movie>(); for (int i = 0; i < cineplexList.size(); i++) { ArrayList<Movie> currentMovieList = cineplexList.get(i).getMovieList(); for (int j = 0; j < currentMovieList.size(); j++) { Movie curMovie = currentMovieList.get(j); boolean pass = true; for (int k = 0; k < movieList.size(); k++) { if (movieList.get(k).getTitle().equals(curMovie.getTitle())) { pass = false; break; } } // add the movie into movieList if (pass) { movieList.add(curMovie); } } } Cineplex.printMovieForUser(movieList); } }
@SuppressWarnings("unchecked") private static void ConfigureHoliday() { System.out.println("\n------------------------"); System.out.println("1) Add Holiday"); System.out.println("2) Remove Holiday"); System.out.println("3) See the holiday list"); System.out.println("\n------------------------"); System.out.println("Please choose the option above"); int holidayOption = scan.nextInt(); if (holidayOption == 1) { System.out.println("please specify "); System.out.print("Year(yyyy): "); int holidayYear = scan.nextInt(); System.out.print("Month(MM): "); int holidayMonth = scan.nextInt(); System.out.print("Day(dd): "); int holidayDay = scan.nextInt(); DateMovie holidayDate = new DateMovie(holidayYear, holidayMonth, holidayDay); System.out.println("Holiday on " + holidayDate.getYearMonthDay() + " has been set"); listHoliday.add(holidayDate); } else if (holidayOption == 2) { System.out.println("Holiday schedule of " + currentCineplex.getCineplexName()); int removeHoliday = getIndexHoliday(); listHoliday.remove(removeHoliday - 1); System.out.println("changes has been saved to the system\n"); } else if (holidayOption == 3) { System.out.println("Holiday schedule of " + currentCineplex.getCineplexName()); for (int i = 0; i < listHoliday.size(); i++) { DateMovie holiday = (DateMovie) listHoliday.get(i); System.out.printf("%d) %s\n", i + 1, holiday.getYearMonthDay()); } System.out.println("\n"); } else { System.out.println("Sorry your input is not listed in our system "); System.out.println("Please choose below option"); System.out.println("1) Quit to " + currentCineplex.getCineplexName() + " configuration"); System.out.println("2) Configure Holiday again"); int option = scan.nextInt(); if (option == 1) { System.out.println(""); return; } else { ConfigureHoliday(); } return; } }
private static void addMovie() { // get the description of the movie from user String title, duration, genre, ratingPG; DateMovie dateMovie; double price; scan.nextLine(); System.out.println("insert the title of new movie"); title = scan.nextLine(); System.out.println("insert the duration of new movie, duration in minute"); duration = scan.nextLine(); System.out.println("insert the genre of the new movie"); genre = chooseMovieType(); scan.nextLine(); System.out.println("insert the RatingPG"); ratingPG = scan.nextLine(); System.out.println("insert the price of the movie in SGD"); price = scan.nextDouble(); System.out.println("insert the director"); scan.nextLine(); String director = scan.nextLine(); System.out.println("How many cast you want to add(at least 2)"); int castNumber = scan.nextInt(); while (castNumber < 2) { System.out.println("please choose at least 2"); System.out.println("How many cast you want to add(at least 2)"); castNumber = scan.nextInt(); } ArrayList<String> castList = new ArrayList<String>(); scan.nextLine(); for (int i = 0; i < castNumber; i++) { System.out.printf("name of cast %d: ", i + 1); String cast = scan.nextLine(); castList.add(cast); } System.out.println("\ninsert the synopsis"); String synopsis = scan.nextLine(); dateMovie = addDateOnNewMovie(title); Movie movie = new Movie(title, duration, ratingPG, genre, dateMovie, price, director, castList, synopsis); if (!dateMovie.getStatus().equals("Coming Soon")) { movieRated.addMovieList(movie); } currentCineplex.addMovie(movie); System.out.println("Changes has been saved to our system\n"); }
private static void editStatusTimeCinema() { System.out.println("Schedule " + currentMovie.getTitle() + " :"); currentMovie.getListDateStatusMovie(); System.out.println("\n"); ArrayList<DateMovie> listMovie = currentMovie.getArrayListOfDateMovie(); System.out.println("Please choose which date you want to configure"); int indexListMovie = scan.nextInt(); DateMovie currentDate = listMovie.get(indexListMovie - 1); System.out.println( "\nPlease choose which one you want to edit on " + currentDate.getStatusTimeMovie()); System.out.println("1) Time"); System.out.println("2) status"); System.out.println("3) cinema"); int timestatus = scan.nextInt(); if (timestatus == 1) { editTime(listMovie.get(indexListMovie - 1)); } else if (timestatus == 2) { System.out.println("insert the new Status"); scan.nextLine(); String newStatus = chooseStatusMovie(); currentDate.setStatus(newStatus); if (!newStatus.equals("Coming Soon")) { movieRated.addMovieList(currentMovie); } } else if (timestatus == 3) { System.out.println("List Cinema: "); int choosenCinema = getIndexCinema(); currentDate.setCinema(currentCineplex.getCinema(choosenCinema - 1)); } else { System.out.println("Sorry your choice is not listed in the system"); System.out.println("Please choose the below option"); System.out.println("1) Quit to Date configuration"); System.out.println("2) Editing Date attribute again"); int option = scan.nextInt(); if (option == 1) { return; } else if (option == 2) { System.out.println(""); editStatusTimeCinema(); return; } return; } }
private static void setNewDateOfMovie(Movie chooseMovie) { System.out.println("insert the new date with format"); System.out.print("YYYY: "); int year = scan.nextInt(); System.out.print("MM: "); int month = scan.nextInt(); System.out.print("DD: "); int day = scan.nextInt(); System.out.print("HH: "); int hour = scan.nextInt(); System.out.print("mm: "); int minute = scan.nextInt(); DateMovie datemovie = new DateMovie(year, month, day, hour, minute); System.out.println("insert status to this new Date " + datemovie.getTime()); scan.nextLine(); String newStatus = chooseStatusMovie(); System.out.println("specify which cinema that will play on " + datemovie.getYearMonthDay()); int cinemaoption = getIndexCinema(); Cinema cinema = currentCineplex.getCinema(cinemaoption - 1); datemovie.setStatus(newStatus); datemovie.setCinema(cinema); currentMovie.setTimeStatus(datemovie); System.out.println("\nYour change has been saved to our system\n"); }
private static void getMovieList() { for (int i = 0; i < currentCineplex.getMovieList().size(); i++) { System.out.println("\n****************************************\n"); System.out.println(currentCineplex.getMovieList().get(i).printDescription()); } }
private static void updatingMovie() { System.out.println("\n------------------------\n"); System.out.println("List movie of " + currentCineplex.getCineplexName() + "............"); for (int i = 0; i < currentCineplex.getMovieList().size(); i++) { System.out.println(i + 1 + ")"); System.out.printf("%s\n", currentCineplex.getMovieList().get(i).printDescription()); } System.out.println("\n------------------------\n"); System.out.println("\nPlease choose one movie to configure\n"); int indexMovie = scan.nextInt(); if (indexMovie > currentCineplex.getMovieList().size()) { System.out.println("Sorry your movie option is invalid"); System.out.println("Please choose again"); updatingMovie(); return; } currentMovie = currentCineplex.getMovie(indexMovie - 1); if (currentCineplex.getMovieList().size() != 0) { // later need to add the Date attribute so it will detect current time and the time when you // put the object System.out.println("What description you want to configure"); System.out.println("1) title"); System.out.println("2) duration"); System.out.println("3) ratingPG"); System.out.println("4) Genre"); System.out.println("5) price"); System.out.println("6) Director"); System.out.println("7) Cast"); System.out.println("8) Synopsis"); System.out.println("9) date and status"); int MovieConfigurationDescription = scan.nextInt(); System.out.flush(); switch (MovieConfigurationDescription) { case 1: System.out.println("insert the new title"); scan.nextLine(); String newTitle = scan.nextLine(); currentMovie.setTitle(newTitle); break; case 2: System.out.println("insert the new duration in minute"); scan.nextLine(); String newDuration = scan.nextLine(); currentMovie.setDuration(newDuration); break; case 3: System.out.println("Set the new RatingPG"); scan.nextLine(); String newRatingPG = scan.nextLine(); currentMovie.setRatingPG(newRatingPG); break; case 4: System.out.println("Set the new Genre of the movie"); scan.nextLine(); String newGenre = chooseMovieType(); currentMovie.setGenre(newGenre); break; case 5: System.out.println("insert the new price of the movie in SGD"); scan.nextLine(); double price = scan.nextDouble(); currentMovie.setPrice(price); break; case 6: System.out.println("insert the new Director of the movie"); scan.nextLine(); String director = scan.nextLine(); currentMovie.setDirector(director); break; case 7: ArrayList<String> listCasting = currentMovie.getCastList(); System.out.println("List of cast: "); for (int i = 0; i < listCasting.size(); i++) { System.out.printf("%d) %s\n", i + 1, listCasting.get(i)); } System.out.println(""); System.out.println("Editting the cast"); System.out.println("1) add new cast"); System.out.println("2) Remove cast"); System.out.println("3) Update new List of cast"); int optionCast = scan.nextInt(); if (optionCast == 1) { System.out.println("insert the new cast "); scan.nextLine(); String newCast = scan.nextLine(); listCasting.add(newCast); } else if (optionCast == 2) { System.out.println("List of cast"); // need to exception int deleteCast = getIndexCast(listCasting); listCasting.remove(deleteCast - 1); } else if (optionCast == 3) { System.out.println("How many cast you want to add"); int castNumber = scan.nextInt(); while (castNumber < 2) { System.out.println("please choose at least 2"); System.out.println("How many cast you want to add(at least 2)"); castNumber = scan.nextInt(); } ArrayList<String> castList = new ArrayList<String>(); scan.nextLine(); for (int i = 0; i < castNumber; i++) { System.out.printf("name of cast %d: ", i + 1); String cast = scan.nextLine(); castList.add(cast); } listCasting = castList; } else { System.out.println("Sorry your option is not listed in our system"); } currentMovie.setCastList(listCasting); break; case 8: System.out.println("insert the new Synopsis"); scan.nextLine(); String synopsis = scan.nextLine(); currentMovie.setSynopsis(synopsis); break; case 9: configuringDate(); break; default: System.out.println("Sorry your choice is not listed in our system"); System.out.println("Please choose the below option"); System.out.println("1) Quit to " + currentCineplex.getCineplexName() + " configuration"); System.out.println("2) Editing Movie again"); int option = scan.nextInt(); if (option == 1) { return; } else if (option == 2) { System.out.println(""); updatingMovie(); return; } } System.out.println("\nchanges has been saved to our system\n"); } else { System.out.println( "\nDont have any movie on the list, please add at least one of the movie to the cinema"); } }
@SuppressWarnings("unchecked") private static void configuring() throws ChoiceException { // get Movie from cineplex while (true) { System.out.println("------------------------"); System.out.println("Configuring " + currentCineplex.getCineplexName()); System.out.println( "1) Add or Remove or see Holiday from " + currentCineplex.getCineplexName()); System.out.println("2) Update the movie from " + currentCineplex.getCineplexName()); System.out.println("3) Add movie to the " + currentCineplex.getCineplexName()); System.out.println("4) Remove movie from " + currentCineplex.getCineplexName()); System.out.println("5) See List of Movie on " + currentCineplex.getCineplexName()); System.out.println("6) Configure another cineplex"); System.out.println("7) Quit"); System.out.println("-------- ----------------"); System.out.println("Please choose the option above"); int OptionMovie = scan.nextInt(); switch (OptionMovie) { case 1: ConfigureHoliday(); break; case 2: if (currentCineplex.getMovieList().size() > 0) { updatingMovie(); } else { System.out.println("Sorry there has no movie in " + currentCineplex.getCineplexName()); } break; case 3: if (currentCineplex.getMovieList().size() > 0) { addMovie(); } else { System.out.println("Sorry there has no movie in " + currentCineplex.getCineplexName()); } break; case 4: if (currentCineplex.getMovieList().size() > 0) { removeMovie(); } else { System.out.println("Sorry there has no movie in " + currentCineplex.getCineplexName()); } break; case 5: getMovieList(); break; case 6: viewCinemaFromDatabase(); return; case 7: System.out.println("Please choose the option below"); System.out.println("1) Quit to the cineplex configuration"); System.out.println("2) Quit from system"); int option = scan.nextInt(); if (option == 1) { viewCinemaFromDatabase(); } else if (option == 2) { System.out.println("Quitting from system"); } return; default: throw new ChoiceException("Sorry your input is not listed in our system"); } cDatabase.writeToDatabase("CineplexDatabase.dat", cineplexList); ratedMovieDatabase.writeToDatabase("RatedMovie.dat", listRatedMovie); holidayDatabase.writeToDatabase("HolidayDatabase.dat", listHoliday); } }