Question: Create a new file calledMovie.java and copy/paste the following starter code into it public class Movie{ // Store rating index private BST years; // Store

Create a new file calledMovie.java and copy/paste the following starter code into it

publicclass Movie{ // Store rating index private BST> years;// Store year index privateclass MovieInfo{ privateString title;// the title of the movie privateString genre;// the genre of the movie, different types are separated by | privateString description;// the description of the movie privateint year;// the year that the movie is produced privateint runtime;// the length of the movie, in minutes privatedouble rating;// the rating of the movie, in 10 scale. smallest increment step: 0.1 privateint votes;// the number of people who voted for this rating publicMovieInfo(String title,String genre,String description,int year,int runtime,double rating,int votes){ this.title= title;this.genre= genre;this.description= description;this.year= year; this.runtime= runtime;this.rating= rating;this.votes= votes; } publicStringtoString(){ return title+","+ genre+","+ description+","+ year+","+ runtime+","+ rating+","+ votes; } } publicMovie(){// Constructor has been provided to you ratings=new BST<>(); years=new BST<>(); } }

In Movie.java, implement a simple movie database indexing program. In this movie database you need to build two indexing BSTs which are already declared in the starter code.

  1. calledyears: theyear of each movie is being used as the key to define the ordering of nodes and each node contains a linked list to store allMovieInfo that was produced in thisyear.
  2. calledratings: therating of each movie is being used as the key to define the ordering of nodes and each node contains a linked list to store allMovieInfo that has thisrating.

Then, add methods that are listed below.

You may not import any package for this part exceptjava.util.Iterator.

Methods

public void addMovie(String title, String genre, String description, int year, int runtime, double rating, int votes)

Add a newMovieInfo to bothyears andratings indexing BST. The ordering of the nodes inLinkedList is up to you. Remember, our LinkedList doesn't allow duplicate keys, using property of each movie such asyearas the key of each node in the list might be invalid.

Parameters: Check the instance variable field of the private classMovieInfo in the starter code for the definition of each parameter.

public void filterYear(int start, int end)

Print movies that were produced fromstart year toend year, both inclusive, by usingyears indexing BST. Print out each movie you found by usingSystem.out.println(). Print nothing ifstartis greater thanend. Sample output:

Each line is constructed by:title + "," + genre + "," + description + "," + year + "," + runtime + "," + rating + "," + votes. You may just use thetoString() method ofMovieInfo from the starter code.

YourfilterYear method is required to have runtime complexity ofOnlogn, assuming you have a balanced tree and (end-start) is a constant.

public void filterRating(double start, double end)

Print movies that have rating value fromstart to theend, both inclusive, by usingratings indexing BST. Print out each movie you found by usingSystem.out.println(). Print nothing ifstart>end. Format requirement is the same as above.

YourfilterRating method is required to have runtime complexity ofOnlogn, assuming you have a balanced tree and (end-start) is a constant.

Warning:

Because of the artifacts of floating point arithmetic, it is safer to use integers in doing increment and then divide by a common factor to get the desired floating number in Java when you want to get an accurate result in floating point increment.

So, instead of using

for(double i=0; i<10.0; i+=0.125){}

You might want to use

for(int n=0; n<=80; n++){double i= n/8.0;}//calculate the desired number

public void removeLowRating(double threshold)

Remove all movies below the specificrating threshold, inclusive. You need to remove movies from both theyears indexing BST and theratings indexing BST. Firstly, remove all movies below the threshold fromratings indexing BST and keep a record of allMovieInfo that is required to be removed. Secondly, find and remove those recordedMovieInfo fromyears indexing BST.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!