You will continue to add functionality to your existing project from the previous task. There is no new repository to clone.
In the previous task, you wrote code to load song and movie data from files into data structures. In this task we'll use this data, and the fact that Song and Movie both inherit from Ratable, to write code that will find the top-rated Songs and Movies. To this end, you will implement the following specs.
MediaLibrary
in the ratings
package.
MediaLibrary
has a constructor that takes no parameters
MediaLibrary
has a method named populateLibrary
that returns void
and takes 3 Strings
as parameters representing filenames for songs with ratings, movies (title and cast),
then movie ratings in this order. These three files will match the three static
methods
you've written in your FileReader
class. The expected behavior of this method will
match the expected behavior of those three methods. This method will read all the data
from all
three files and store all the Songs and Movies as part of the state of the
MediaLibrary
object
MediaLibrary
has a method named topKRatables
that takes an
int
and returns an ArrayList
of Ratables
. This method will return the top k ratables that have been loaded using
the populateLibrary
method where k is the input int
(eg. topKRatables(10)
returns a top 10 list).
The ratables will be ranked by their bayesian average rating with 2 extra ratings of
value 3 in decreasing order (eg. The ratable with the highest bayesian average should
be at index 0). If k is greater than the number of ratables, return all ratables (eg.
If k is 100 and there are only 3 ratables in the library, return all 3).
populateLibrary
reads the data properly, you must call the topKRatables
as there is no other way -
that is defined in this document and can be used in testing - to access the state of
the MediaLibrary
object
Songs
and Movies
have unique titles.
When
testing topKRatables
, if the returned ArrayList
contains the correct titles in the
correct order, your test should pass (ie. you don't have to check any other instance
variables like the ratings linked list, song ids, artists, or cast members)
TestClasses3: Create a class named TestClasses3
in the tests
package and
write the following testing utility method in this class.
compareRatableArrayLists
- Write a method named compareRatableArrayLists
in the
tests.TestClasses3
class that:
ArrayList<Ratable>
objects as parameters
ArrayLists
contain Ratables
with the same titles in the same order.
The method fails a JUnit
assert if the ArrayLists
do not contain ratables with the same titles in the same order
Note: This utility method is simpler than the one from the previous task. Don't overthink it.
Write tests for the MediaLibrary
class by calling populateLibrary
, then check that
topKRatables
returns the expected songs and movies in the expected order
Testing with files should follow the same structure as task 6 (eg. all test files should be in the "data" directory)
Note: Do not add spaces in your testing filename. Use underscores like in the examples above if you want to use filenames with multiple words.
Implement all the methods of the MediaLibrary
class.
The feedback in Autolab will be given in 4 phases. If you don't complete a phase, then feedback for the following phase(s) will not be provided.
Once you complete all 4 phases, you will have completed this Task and Autolab will confirm this with a score of 1.0 for complete.