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

    System.out.println("\n=== Displaying Movie ===");
    int i = 0;
    Movie movie = null;
    MovieSerializer serializer = new MovieSerializer();
    Scanner sc = new Scanner(System.in);

    do {
      if (i != 0) System.out.println(i + ". " + movie.getMovieTitle());
      movie = serializer.deSerializeMovie(rm.getFileName());
      i++;
    } while (movie != null);

    ReadMovie.resetI();

    if (movie == null && i == 1) {
      System.out.println("== NO MOVIE FOUND ==");
      return;
    }
    int userInput = -1;

    do {
      System.out.println("\nOption:  ");
      System.out.println("1: View movie's detail ");
      System.out.println("0: Back to main menu");
      System.out.print("Enter your option: ");

      try {
        userInput = sc.nextInt();
      } catch (InputMismatchException exception) {
        System.out.println("\nPlease enter correct input!");
        userInput = -1;
        sc.nextLine();
      }

      switch (userInput) {
        case 1:
          printMovie(rm);
          break;
        default:
          break;
      }

    } while (userInput != 0);

    return;
  }
Ejemplo n.º 2
0
  public static void deleteMovie(ReadMovie rm) {
    Scanner sc = new Scanner(System.in);

    System.out.println("\n=== DELETING MOVIE ===");
    System.out.println("Enter the movie that you want to delete : ");
    String movieName = sc.nextLine();

    System.out.println("Deleting " + movieName + "...");
    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.");
        return;
      }
    } catch (Exception e) {
      e.printStackTrace();
      return;
    }

    System.out.println("Movie deleted!");
    rm.deleteFileName(movieName);
  }
Ejemplo n.º 3
0
  public static Movie[] reverseMovie(ReadMovie rm) {
    System.out.println("\n===== Latest Added Movies =====");
    if (rm.getAmount() == 0) return null;
    int i = 0, k = 0;
    Movie[] sortedMovieList = new Movie[rm.getAmount()];
    MovieSerializer movieSerializer = new MovieSerializer();

    rm.reverseI();
    do {
      sortedMovieList[k] = movieSerializer.deSerializeMovie(rm.getReverseFileName());
      if (sortedMovieList[k] != null) {
        if (sortedMovieList[k].getShowingStatus().equals("End of Showing"))
          sortedMovieList[k] = null;
        else k++;
        i++;
      }
    } while (i < rm.getAmount());

    ReadMovie.resetI();

    if (sortedMovieList[0] == null) {
      System.out.println("== NO MOVIE FOUND ==");
      return null;
    }

    return sortedMovieList;
  }
Ejemplo n.º 4
0
  public static Movie[] sortBySales(ReadMovie rm) // sort movie by rating with insert sort
      {
    System.out.println("\n===== Top Movies by Sales =====");
    if (rm.getAmount() == 0) return null;
    Movie key, temp;
    int i = 0, k = 0;
    Movie[] sortedMovieList = new Movie[rm.getAmount()];
    MovieSerializer serializer = new MovieSerializer();

    do {
      sortedMovieList[k] = serializer.deSerializeMovie(rm.getFileName());
      if (sortedMovieList[k].getShowingStatus().equals("End of Showing")) sortedMovieList[k] = null;
      else k++;
      i++;
    } while (i < rm.getAmount());

    ReadMovie.resetI();

    if (sortedMovieList[0] == null) {
      System.out.println("== NO MOVIE FOUND ==");
      return null;
    }

    for (int j = 1; j < k; j++) {
      key = sortedMovieList[j];
      int position = j;
      while (position > 0
          && (sortedMovieList[position].getTicketSales()
              > sortedMovieList[position - 1].getTicketSales())) {
        temp = sortedMovieList[position];
        sortedMovieList[position] = sortedMovieList[position - 1];
        sortedMovieList[position - 1] = temp;
        position--;
      }
      sortedMovieList[position] = key;
    }
    return sortedMovieList;
  }
Ejemplo n.º 5
0
  public static Movie pickMovie(ReadMovie rm) {

    int i = 0, userInput;

    if (rm.getAmount() == 0) {
      System.out.println("== NO MOVIE FOUND ==");
      return null;
    }

    Movie[] movie = new Movie[rm.getAmount()];
    MovieSerializer serializer = new MovieSerializer();
    Scanner sc = new Scanner(System.in);

    do {
      if (i != 0) System.out.println(i + ". " + movie[i - 1].getMovieTitle());
      movie[i] = serializer.deSerializeMovie(rm.getFileName());
      i++;
    } while (i < rm.getAmount());
    System.out.println(i + ". " + movie[i - 1].getMovieTitle());
    ReadMovie.resetI();

    System.out.println("\nPlease choose a movie:  (Enter -1 to quit)");
    do {
      try {
        userInput = sc.nextInt();
      } catch (InputMismatchException exception) {
        System.out.println("\nPlease enter correct input!");
        userInput = -1;
        sc.nextLine();
      }
      if (userInput > i || userInput <= 0) continue;
      else return movie[userInput - 1];
    } while (userInput != -1);

    return null;
  }
Ejemplo n.º 6
0
  public static Movie[] sortByRating(ReadMovie rm) // sort movie by rating with insert sort
      {
    System.out.println("\n===== Top Movies by Ratings =====");
    if (rm.getAmount() == 0) return null;
    Movie key, temp;
    int i = 0, k = 0;
    Movie[] movieList = new Movie[rm.getAmount()], sortedMovieList = new Movie[rm.getAmount()];
    MovieSerializer serializer = new MovieSerializer();

    do { // problem
      sortedMovieList[k] = serializer.deSerializeMovie(rm.getFileName());
      if ((sortedMovieList[k].getShowingStatus().equals("End of Showing"))
          || (sortedMovieList[k].averageMovieRating() == -1)) sortedMovieList[k] = null;
      else k++;
      i++;
    } while (i < rm.getAmount());

    ReadMovie.resetI();

    if (sortedMovieList[0] == null) return null;

    for (int l = 1; l < k; l++) {
      key = sortedMovieList[l];
      int position = l;
      while (position > 0
          && (sortedMovieList[position].averageMovieRating()
              > sortedMovieList[position - 1].averageMovieRating())) {
        temp = sortedMovieList[position];
        sortedMovieList[position] = sortedMovieList[position - 1];
        sortedMovieList[position - 1] = temp;
        position--;
      }
      sortedMovieList[position] = key;
    }
    return sortedMovieList;
  }
Ejemplo n.º 7
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;
  }