You will continue to add functionality to your existing project from the previous task. There is no new repository to clone.
In this task, you will implement the following specs.
ratings.datastructures.BinaryTreeNode
class that has been provided in the handout repo.
An object of this type will be returned by one
of your methods and will be tested in Autolab.
Just like the LinkedListNode
class, all these methods must exist and be named exactly as
they are in the repo or there will be errors during grading. You may add additional methods to this
class, but don't call those methods from your tests.
Create a Playlist
class in the ratings package with the following functionality. This class
will
use a Binary Search Tree (BST) to store a playlist of Songs
in sorted order. This class will
have the following behavior:
Comparator
of Songs
addSong
that takes a reference to a Song
and returns
void
getSongTree
that takes no parameters and returns the
BinaryTreeNode
of Songs
that is the root node of your
BST. This method should be a getter with one line of code
getSongList
that takes a BinaryTreeNode
of Songs
as a parameter and returns a LinkedListNode
of Songs
getSongList
that takes no parameters and returns a
LinkedListNode
of Songs
getSongList
method
with
the root of your BST as the argument
getSongList
method so you can run your tests and utilize the
debugger
while writing your code
SongTitleComparator
, the songs will be sorted
alphabetically by title
SongBayesianRatingComparator
, the songs will be sorted
in
decreasing order (The highest rated songs first) according to their bayesian
average rating with 2 fake ratings of 3 being added
TestDataStructures2: Create a class named TestDataStructures2
in the tests package and
write the
following testing utility method in this class.
compareSongTrees
- Write a method named compareSongTrees
in the
tests.TestDataStructures2
class that:
BinaryTreeNode<Song>
objects as parameters
You'll have the need to compare 2 song objects throughout this method.
Luckily, you already wrote, and tested, a compareSongs
method that does
this (You may want to add a call to your compareListsOfRatings
to compare the ratings of the
two songs since we did not have ratings where we wrote the compareSongs
method). Since the
method is in a different class and is non-static, you'll need to create a new
TestClasses1
object
and call your method through that object. Note that you do not have to
import TestClasses1
since it's in the same package as TestDataStructures2
Note: You still have to create every class and method from the specification before getting feedback on your submission in Autolab since the grader will not be able to compile if those classes/methods do not exist. You don't have to implement them yet, and they can all return a default value
TestDataStructures2: Add tests to the TestDataStructures2 class in the tests package that will test the following functionality.
ratings.Playlist
- Write tests for the following methods of the Playlist
class
Comparator<Song>
. In your testing, you can pass
either a
new SongTitleComparator
or a new SongBayesianRatingComparator
. This is allowed through the magic of
Polymorphism which we'll discuss in greater detail later in the semester
addSong
method to populate the playlist with test data
getSongTree
method and assert that it returns a tree that
contains all the songs in the correct places based on the comparator you provided in the
constructor and the algorithm for inserting into a BST
getSongList
method that takes no parameters and assert that it
returns a linked list
of all the added songs in sorted order according to the comparator you provided in the
constructor
getSongList
method that takes
a tree as a parameter, though it will be tested implicitly since the one you are
testing should call the other
Implement all the classes/methods described in the Specification section. As you're writing this code, you should run your tests to see how you are progressing. It's recommended that you write your tests first, submit to Autolab to make sure you have good testing, then use those verified tests, along with the debugger, to check your code.
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.