Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?

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

Posted on 2017-10-12
1
Low Priority
?
32 Views
Last Modified: 2017-10-16
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){
this.ratings.add(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>();

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


}}


catch (IOException ex){
ex.printStackTrace();
}
return (songs);
}
0
Comment
Question by:Amanda Johnson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 86

Expert Comment

by:CEHJ
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?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question