Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CSE116: Computer Science 2

Programming Task 5

Classes 2

Time Estimate: 3 hours

Requirements

Project Structure

You will continue to add functionality to your existing project from the previous task. There is no new repository to clone.

Testing Requirements

There are no additional testing requirements for this task. Use the tests you wrote in programming task 4 (In the TestClasses2 class) to help you debug your code in this task. You are encouraged to write more than the tests that were required for task 4 to help you implement the rest of the functionality for this task. You may find that even writing code that passes your tests is not enough to earn credit for this task.

Programming Requirements

Recall when you wrote your tests for the Song and Movie classes which had much of the same functionality. Specifically, your tests for the bayesianAverageRating method could be the same for both classes and you effectively had duplicate tests. Now, we;ll see that there's a better way for classes to share code with each other. Both Song and Movie will extend a Ratable class that will contain all the common code that these classes share.

ratings.Ratable - In the ratings package, create a class named Ratable

This class will use the default constructor that takes no parameters (You don't have to write any constructor

Remove all functionality related to title and ratings from the Song class and add to the Ratable class. This includes title and ratings (LinkedListNode of Ratings) instance variables and all of the following methods

getTitle

setTitle

addRating

getRatings

averageRating

didReviewerRateSong

removeRatingByReviewer

ratings.Song - Update the Song class to inherit from the Ratable class

You removed 2 instance variables and 6 methods from this class while writing the Ratable class. However, Song will now inherit all those variables and methods from the Ratable class

You should verify that your Song class does inherit this functionality by running the TestClasses1 tests and verifying that they all still pass even though that code is not in the Song class itself.

At this point, the Song class should only have instance variables for the artist and id as well as the following methods with all other state and behavior inherited from Ratable:

A constructor that takes 3 Strings

getArtist

setArtist

getSongID

setSongID

Since the Ratable class does not have a constructor, you should call setTitle in the Song constructor to set the value of the title instance variable. Alternatively, you may add a Ratable constructor that takes the title as a parameter and call the super constructor in the Song constructor.

ratings.Movie - Implement the following in the Movie class that you've tested during task 4

Movie will inherit from the Ratable class

Movie will have a constructor that takes a String and an ArrayList of Strings

The String represents the title of the Movie and should be set using the setTitle method inherited from Ratable

The ArrayList contains the names of the cast of the Movie and should be stored in an instance variable

Implement a getter for the cast named getCast that returns an ArrayList of Strings

ratings.Ratable - Update the Ratable class with the bayesianAverageRating method

Now that both Song and Movie inherit from Ratable, any functionality added to Ratable will be added to both Songs and Movies. In task 4, you tested a bayesianAverageRating method in both Song and Movie. In this task, you will only implement this method in Ratable and your tests for both Song and Movie will pass when you are finished.

Implement bayesianAverageRating

This method takes 2 ints as a parameters. The first int is the number of fake ratings and the second is the value of those ratings

The method returns the Bayesian average of the Ratable if the extra rating were added

Important: Do not actually add the fake ratings to you Linked List of Ratings. This method should not have any side effects (ie. It should not change the state of any objects on the heap). You can test for this by calling bayesianAverageRating twice on the same Song/Movie with the same arguments and make sure you get the same result both times.

ratings.Ratable - Update the Ratable class with the bayesianAverageRating method

Now that both Song and Movie inherit from Ratable, any functionality added to Ratable will be added to both Songs and Movies. In task 4, you tested a bayesianAverageRating method in both Song and Movie. In this task, you will only implement this method in Ratable and your tests for both Song and Movie will pass when you are finished.

Implement bayesianAverageRating

This method takes 2 ints as a parameters. The first int is the number of fake ratings and the second is the value of those ratings

The method returns the Bayesian average of the Ratable if the extra rating were added

Important: Do not actually add the fake ratings to you Linked List of Ratings. This method should not have any side effects (ie. It should not change the state of any objects on the heap). You can test for this by calling bayesianAverageRating twice on the same Song/Movie with the same arguments and make sure you get the same result both times.

ratings.datastructures.Comparator - Add the comparator class to your project in the ratings.datastructures package

This class will take a generic type parameter

This class uses the default constructor - You do not have to write a constructor

This class has a method named compare that takes 2 parameters, both of the type of the generic

This method can return false on all inputs. It will be overridden by child classes

ratings.datastructures.SongTitleComparator - Implement the SongTitleComparator that will be used to sort Songs by their title in alphabetical order

This class will inherit from the Comparator class with the generic type being Song

Override the compare method to take two references to Song objects and returns a boolean

This method returns true if the first parameter should come before the second in sorted order, and false otherwise

Comparisons should be made using the Strings compareToIgnoreCase method. You are not expected to check the characters of the Strings to determine their order

ratings.datastructures.SongBayesianRatingComparator - Implement the SongBayesianRatingComparator that will be used to sort Songs by their bayesian average rating in decreasing order

This class will inherit from the Comparator class with the generic type being Song

Override the compare method to take two references to Song objects and returns a boolean

This method returns true if the first parameter has a higher bayesian average than the second in, and false otherwise

Use 2 extra ratings with value 3 for the bayesian averages

AutoLab Feedback

Since the tests are provided for you in this task, there is only one phase of AutoLab feedback.

1. Running my tests on Your Solution

AutoLab will run my tests against your code to check it for correctness. If you are running, and passing, the provided tests before submitting, you should pass all the tests in AutoLab.

Once you passed the tests, you will have completed this Task and AutoLab will confirm this with a score of 1 for complete.

Wednesday, March 15 @ 9:00 AM

Expected Deadline

Wednesday, March 29 @ 9:00 AM

Deadline