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
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.
- 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.
- 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
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
Get step-by-step solutions from verified subject matter experts
