Ejemplo n.º 1
0
  public static void addMovie(ReadMovie rm) {

    Scanner sc = new Scanner(System.in);
    int userInput = -1;

    System.out.println("\n=== We are going to create a movie. === ");
    System.out.print("Please enter a movie name: ");

    String movieName = sc.nextLine();
    Movie mov = new Movie(movieName);
    System.out.println("The movie \"" + movieName + "\" has been created.");

    while (userInput < 9) {
      System.out.println("========= Adding details to \"" + mov.getMovieTitle() + "\" ========== ");
      System.out.println("1.  Add movie rating (G, PG, PG13, NC16, M18, R21)");
      System.out.println("2.  Add/change showing status");
      System.out.println("3.  Add genre of movie (Adventure, Drama, etc)");
      System.out.println("4.  Add synopsis");
      System.out.println("5.  Add director's name");
      System.out.println("6.  Add movie's duration");
      System.out.println("7.  Add cast's name");
      System.out.println("8.  Add movie type");
      System.out.println("9. Exit");
      System.out.print("Enter your options: ");
      try {
        userInput = sc.nextInt();
      } catch (InputMismatchException exception) {
        System.out.println("\nPlease enter correct input!");
        userInput = -1;
        sc.nextLine();
      }
      sc.nextLine();
      switch (userInput) {
        case 1:
          System.out.println("Enter movie rating: ");
          mov.setMovieRating(sc.nextLine());
          break;
        case 2:
          System.out.println("Press \'1\' for \"Coming Soon\"");
          System.out.println("Press \'2\' for \"Preview\"");
          System.out.println("Press \'3\' for \"Now Showing\"");
          System.out.println("Press \'4\' for \"End of Showing\"");
          try {
            mov.setShowingStatus(sc.nextInt());
          } catch (InputMismatchException exception) {
            System.out.println("\nPlease enter correct input!");
            sc.nextLine();
          }
          break;
        case 3:
          System.out.println("Enter genre of movie: ");
          mov.addGenre(sc.nextLine());
          break;
        case 4:
          System.out.println("Enter synopsis: ");
          mov.setSynopsis(sc.nextLine());
          break;
        case 5:
          System.out.println("Enter director's name: ");
          mov.setDirectorName(sc.nextLine());
          break;
        case 6:
          System.out.println("Enter movie's duration: ");
          mov.setMovieDuration(sc.nextInt());
          break;
        case 7:
          System.out.println("Enter cast's name: ");
          mov.addCastName(sc.nextLine());
          break;
        case 8:
          System.out.println("Press \'1\' for \"Normal\"");
          System.out.println("Press \'2\' for \"Blockbuster\"");
          try {
            mov.setMovieType(sc.nextInt());
          } catch (InputMismatchException exception) {
            System.out.println("\nPlease enter correct input!");
            sc.nextLine();
          }
          break;
        default:
          break;
      }
    }

    System.out.println("Storing movie...");
    MovieSerializer serializer = new MovieSerializer();
    serializer.serializeMovie(mov);
    System.out.println("Movie creation completed!");
    rm.storeFileName(mov.getMovieTitle());

    return;
  }
Ejemplo n.º 2
0
  public static void editMovie() {
    Scanner sc = new Scanner(System.in);
    int userInput = -1;
    MovieSerializer serializer = new MovieSerializer();

    System.out.println("\n=== Editing Movie ===");
    System.out.println("Enter the movie that you want to edit: ");
    String movieName = sc.nextLine();
    Movie mov = serializer.deSerializeMovie(movieName);

    if (mov == null) {
      return;
    }
    while (userInput < 10) {
      System.out.println("========= Adding details to \"" + mov.getMovieTitle() + "\" ========== ");
      System.out.println("1.  Edit movie name");
      System.out.println("2.  Edit movie rating (G, PG, PG13, NC16, M18, R21)");
      System.out.println("3.  Add/change showing status");
      System.out.println("4.  Add genre of movie (Adventure, Drama, etc)");
      System.out.println("5.  Edit synopsis");
      System.out.println("6.  Edit director's name");
      System.out.println("7.  Edit movie's duration");
      System.out.println("8.  Edit cast's name");
      System.out.println("9.  Edit movie type");
      System.out.println("10. Exit");
      System.out.println("Enter your options: ");
      try {
        userInput = sc.nextInt();
      } catch (InputMismatchException exception) {
        System.out.println("\nPlease enter correct input!");
        userInput = -1;
        sc.nextLine();
      }
      sc.nextLine();
      switch (userInput) {
        case 1:
          System.out.println("Enter movie name: ");
          mov.setMovieTitle(sc.nextLine());
          System.out.println("New movie title: " + mov.getMovieTitle());
          break;
        case 2:
          System.out.println("Enter movie rating: ");
          mov.setMovieRating(sc.nextLine());
          System.out.println("New movie rating: " + mov.getMovieRating());
          break;
        case 3:
          System.out.println("Press \'1\' for \"Coming Soon\"");
          System.out.println("Press \'2\' for \"Preview\"");
          System.out.println("Press \'3\' for \"Now Showing\"");
          System.out.println("Press \'4\' for \"End of Showing\"");
          mov.setShowingStatus(sc.nextInt());
          sc.nextLine();
          System.out.println("New showing status: " + mov.getShowingStatus());
          break;
        case 4:
          System.out.println("Enter genre of movie: ");
          mov.addGenre(sc.nextLine());
          System.out.println("All genres of movie: " + mov.getGenre());
          break;
        case 5:
          System.out.println("Enter synopsis: ");
          mov.setSynopsis(sc.nextLine());
          System.out.println("New synopsis: ");
          mov.printSynopsis();
          break;
        case 6:
          System.out.println("Enter director's name: ");
          mov.setDirectorName(sc.nextLine());
          System.out.println("New director's name: " + mov.getDirectorName());
          break;
        case 7:
          System.out.println("Enter movie's duration: ");
          mov.setMovieDuration(sc.nextInt());
          sc.nextLine();
          System.out.println("New movie's duration: " + mov.getMovieDuration() + " minutes");
          break;
        case 8:
          System.out.println("Enter cast's name: ");
          mov.addCastName(sc.nextLine());
          System.out.println("All casts' names: " + "\t" + mov.getCastName());
          break;
        case 9:
          System.out.println("Press \'1\' for \"Normal\"");
          System.out.println("Press \'2\' for \"Blockbuster\"");
          mov.setMovieType(sc.nextInt());
          sc.nextLine();
          System.out.println("New movie type: " + mov.getMovieType());
          break;
        default:
          break;
      }
    }
    System.out.println("Storing movie...");
    serializer.serializeMovie(mov);
    System.out.println("Done.");

    if (movieName.equalsIgnoreCase(mov.getMovieTitle())) {
      return;
    } else {
      System.out.println("Deleting original serializable file...");
      try {
        File file = new File(movieName + ".ser");

        if (file.delete()) {
          System.out.println(file.getName() + " is deleted.");
        } else {
          System.out.println("Fail to delete file.");
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }