Question: [Java] Can you verify if I wrote the proper code (according to the parameters)? And if I didn't, can you fix whatver was wrong with
[Java]
Can you verify if I wrote the proper code (according to the parameters)? And if I didn't, can you fix whatver was wrong with it?
1. Create a class named "RatingsAnalyzer" in the ratings package. In this new class, write a public static method named "bayesianAverage" that takes three parameters (an ArrayList of Doubles, an int, then a double) and returns a double. The first parameter represents all the ratings for a particular item, the second parameter is the number of additional ratings to add, and the third parameter is the value of these additional ratings. The return value is the bayesian average of these ratings based on these parameters.
My code:
package ratings;
import java.util.ArrayList;
public class RatingsAnalyzer { private ArrayList
public RatingsAnalyzer(ArrayList
// Calculate Bayesian Avergae public static double bayesianAverage(ArrayList
2. Create a package named "ratables" inside the ratings package. In the newly created ratables package, create a class named "Song" containing the following methods. Note that none of these methods are static since they will belong to instances of the Song class and not the class itself:
i. A public constructor taking three Strings as parameters in the order (youTubeID, artist, title). These values must be stored in instance variables of your choosing
ii. A public method named "getID" that takes no parameters and returns the youTubeID that was provided when the constructor was called as a String
iii. A public method named "getLink" that takes no parameters and return the YouTube url for this song as a String. The url must be in the format "https://www.youtube.com/watch?v=###########" with ########### replaced with the youTubeID for this song
iv. A public method named "getDescription" that takes no parameters and returns a String containing the artist and title provided when the constructor was called. The format of this description must be "artist - title", as in the artist of the song then the title of the song separated by the String " - "
v. A public method named "addRating" that takes a double as a parameter and returns void. The double represents a rating made for this song which must be stored in an instance variable. Note that this method will be called each time a new rating in found for the same song and all ratings must be stored in an instance variable
vi. A public method named "getRatings" that takes no parameters and returns an ArrayList of Doubles containing every rating that was added to this song with the addRating method
vii. [optional] You may add any other methods or instance variables that will help you complete the project objectives. For example, it is helpful to override the toString method so you can print out songs while testing your program to verify the output
My code:
package ratables;
import java.util.ArrayList;
public class Song {
// Instance variables private String youTubeID; private String artist; private String title; // Constructor public Song(String youTubeID, String artist, String title) { this.youTubeID = youTubeID; this.artist = artist; this.title = title; } // Get the id of the youtube video public String getID() { return youTubeID; } // Get the link of the song of the youtube video public String getLink() { String youtubeIDTemplate = "https://www.youtube.com/watch?v=###########"; String songLink = youtubeIDTemplate.replaceAll("###########", youTubeID); return songLink; } // Get the song's artist and title public String getDescription() { String songInfo = artist + " - " + title; return songInfo; } // Add a rating to a song & return all of the ratings for a song private ArrayList
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
