JAVA CSV to Hash Map update rating when adding a new entry

Totally new at coding. Having a really tough time on the following assignment. This is the first task, and I cannot go on to finish the other three tasks until I master this one:

I need to return a hash map of YouTubeID's to Song objects containing all the information from a csv file. I am provided a filename for a csv file containing song ratings. Each line of these files will include: YouTubeID,artist,songName,rating. The YouTubeID is to be the key in the hashmap, the values will be Song objects containing the information for each file. The Song object is (String, String, String)

When a song has multiple ratings in the file I cannot just add the original song a second time, or it will over write the first instance. I only want to add another rating to the existing song entry in the map. We are given an addRating method that is supposed to help:

public void addRating(int rating){

I am having difficulty with the part where I add the song to the map without overwriting and only add the rating. I know I need to do something with the "Song" object but I have no idea what. The code I have thus far is:

public HashMap<String, Song> readCSVFile(String filename){
HashMap<String,Song> songs = new HashMap<String,Song>();

for(String line : Files.readAllLines(Paths.get(filename))){
String allValues = line;
String[] data = allValues.split(",");


catch (IOException ex){
return (songs);
Amanda JohnsonAsked:
Who is Participating?
The Song object is (String, String, String)
I'm wondering why the last parameter (presumably 'rating') is of type String, when addRating takes an int?
All Courses

From novice to tech pro — start learning today.