Object Oriented Review

Objectives
  • Analyze and filter real world data.

  • Create multiple constructors.

  • Learn about method and constructor overloading.

  • Explore the toString and equals method.

Getting Started

Create a new Java project called L5 and import RottenTomatoes-starter.jar. Your directory should look like this:

L5/
├── resources
│   ├── movie_actors.dat
│   ├── movie_countries.dat
│   ├── movie_directors.dat
│   ├── movie_genres.dat
│   ├── movie_locations.dat
│   ├── movie_ratings.dat
│   ├── movie_keywords.dat
│   ├── movie_titles.dat
│   ├── movie_years.dat
│   ├── keywords.dat
│   ├── user_ratings.dat
│   ├── user_keywords.dat
│   └── readme.txt
└── src
    ├── Movie.java
    ├── MovieLibrary.java
    ├── Rating.java
    └── KeyWord.java
    └── FileParser.java

The project will initially have a number of errors until you complete the specified methods.

Data

The data for this assignment was collected and reformatted from the following website. If you are interested, the provided readme has a description of the data formats and some additional information.

Description

You will be creating a MovieLibrary to store information from over 10,000 movies. Each Movie instance will store basic information, RottenTomato ratings, and list of keywords that describe the movie. Once created, you will create methods to filter given specific conditions and format the output.

The KeyWord Class

This class consists of a descriptive word and the frequency that word appears.

The completed KeyWord class has been provided to serve as a template for other classes.

Java specifies that member/instance variables are called fields.
The KeyWord class has the following fields:

  • A private String to store the keyword

  • A private int to store the frequency

Use the javadoc to understand the KeyWord class. Use the code in the main method to test your class.

The Rating Class

This is a class where ratings from RottenTomato are stored.

Declare the following fields:

  • A private double to store the average critic score

  • A private int to store the number of critics in the critic score

  • A private double to store the average audience score

  • A private int to store the number of people included in the audience score

Use the javadoc to declare and implement the rest of the methods.

Tip
Declare and implement the four argument constructor first. Explicitly invoke this constructor when implementing the noargs constructor by using the this keyword.

Once you are finished, use the code in the main method to test your class.

The Movie Class

This class creates a Movie object. A Movie object requires a title, year, and list of actors. A Movie object can also have a list of genres, a Rating, and a list of KeyWords.

Declare the following fields:

  • A private final String to store the title of the movie

  • A private final int to store the year

  • A private final List<String> to store the actors

  • A private List<String> to store the genres

  • A private Rating to store the movie rating

  • A private List<KeyWord> to store keywords used to describe the movie

You will construct an equals method for this class. Read these additional notes before implementation.

Use the javadoc to declare and implement the rest of the methods. Once you are finished, use the code in the main method to test your class.

The MovieLibrary Class

This is where the Movie objects are stored.

Declare the following fields:

  • a private List<Movie> of movies

Use the javadoc to declare and implement the rest of the methods.

Once you have finished implementing the code, uncomment the first two lines in in the main method of your MovieLibrary class which:

  • Create an instance of FileParser.

  • Create an instance MovieLibrary using the return value of the getAllMovies in the FileParser class. Use the following file names for the arguments:

"resources/movie_titles.dat"
"resources/movie_years.dat"
"resources/movie_actors.dat"
"resources/movie_genres.dat"
"resources/keywords.dat"
"resources/movie_keywords.dat"
"resources/movie_ratings.dat"
  • Find the questions below in the main method of your MovieLibrary class.
    Answer each question and supplement the answer with the code you used.

System.out.println("The MovieLibrary class:");
// 1. How many movies are there in total?

// Notice that the scores in the Ratings class are integers from 0 to 100, inclusive.
// 2. How many movies did the audience rate 95% or above?
//    Hint: check for movies that score 95 or above

// 3. How many movies did the critics rate 0% to 5%, inclusive?

// 4. Some movies don't have KeyWords. Explain how you could change
//   the getDescription method to only print movies that have keywords.

// 5. How would you sort the KeyWords by frequency? What class/classes would you modify?
// How would you deal with keywords that have the same frequency?

Important
Once you have completed the code and answered the questions, show your code to the TA or helper.