Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- //import com.google.gson.Gson;
- //import com.google.gson.GsonBuilder;
- // author @btcworker - Gene Cotillo
- //line 74 or so will have my comments, but essentially i made all the variables defined right here static. Started getting the null pointer exception
- //I added values after i got it the first time, before they were not initialized since i initialize them below.
- public class Movie {
- public static String title = "A";
- public static String overview = "B";
- public static String releaseDate = "C";
- public static String director = "D";
- public static String genreName = "Action" ;
- public static String[] genre = {"Drama", "Action", "Comedy", "Horror"};
- private static ArrayList<Movie> movieA;
- public Movie() {
- movieA = new ArrayList<Movie>();
- }
- public Movie(String mTitle, String mOverview, String mReleaseDate, String mDirector, String mGenreName) {
- title = mTitle;
- overview = mOverview;
- releaseDate = mReleaseDate;
- director = mDirector;
- genreName = mGenreName;
- }
- public static void addMovie(String mTitle, String mOverview, String mReleaseDate, String mDirector, String mGenreName) {
- Scanner in = new Scanner(System.in);
- int time = 1000;
- System.out.println("Please enter the information about your movie below.");
- System.out.println();
- sleeper(time);
- System.out.print("What is the name of your movie?" );
- mTitle = in.nextLine();
- System.out.println();
- sleeper(time);
- System.out.print("Give a short description of what the movie is about: ");
- mOverview = in.nextLine();
- System.out.println();
- sleeper(time);
- System.out.print("What year did the movie come out? ");
- mReleaseDate = in.nextLine();
- System.out.println();
- sleeper(time);
- System.out.print("What is the name of the director of the film? ");
- mDirector = in.nextLine();
- System.out.println();
- sleeper(time);
- System.out.println("What Genre best describes the movie? ");
- sleeper(600);
- System.out.print("Type 1 for Drama, 2 for Action, 3 for Comedy or 4 for Horror" );
- int userGenre = in.nextInt();
- if (userGenre == 1) {
- genreName = genre[0];
- }
- else if (userGenre == 2) {
- genreName = genre[1];
- }
- else if (userGenre == 3) {
- genreName = genre[2];
- }
- else if (userGenre == 4) {
- genreName = genre[3];
- }
- else {
- System.out.println("You have entered an invalid entry for genre. We will use the default genre.");
- genreName = genre[0];
- }
- //Everything was working fine until I changed these variables, which are called in the class above, to static.
- //Only did so because Eclipse told me too... Now i get a null pointer exception when trying to type the interger for the genre choice.
- movieA.add(new Movie(title, overview, releaseDate, director, genreName));
- sleeper(1200);
- System.out.println();
- System.out.print("Would you like to enter another movie? type 1 for yes or 2 for no");
- int moreMovies = in.nextInt();
- in.close();
- if (moreMovies == 1) {
- start();
- }
- else {
- System.out.println(movieA.toString().replaceAll("\\[\\]", ""));
- //originally, i was going to turn the arrayList into an object and then use json to print it out.
- //worked well, but then i changed the code.
- /*
- * Gson gson = new GsonBuilder().setPrettyPrinting().create();
- * String json = gson.toJson();
- * System.out.println("Here are the details for the movies entered:");
- * System.out.println();
- * System.out.println(json);
- */
- }
- }
- public static void main(String[] args) {
- start();
- }
- public static void start() {
- System.out.println("Welcome to The movie list builder!");
- sleeper(900);
- addMovie(title, overview, releaseDate, director, genreName);
- }
- public static void startOver()
- {
- System.out.println("Get ready to enter the info for your next movie.");
- System.out.println();
- sleeper(900);
- addMovie(title, overview, releaseDate, director, genreName);
- }
- public static void sleeper(int time) {
- try {
- Thread.sleep(time);
- } catch(InterruptedException ex) {
- Thread.currentThread().interrupt();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement