Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The SongsDatabase class keeps tracks of song titles by classifying them according to genre (e.g., Pop, Rock, etc.).The class uses a HashMap to map a

TheSongsDatabaseclass keeps tracks of song titles by classifying them according to genre (e.g., Pop, Rock, etc.).The class uses a HashMap to map a genre with a set of songs that belong to such a genre.The set of songs will be represented using a HashSet. You must implement the following:

  1. Provide a definition for the required map. This definition would appear where you see the comments

// You must provide the initialization

  1. Implement theaddSongThis method adds a song to the set associated with the specified genre.If there is not set associated with the genre, one will be added to the map.
  2. Implement thegetGenreOfSong. The method will return the genre for the specified song or null if the song is not part of the database.

public class SongsDatabase {

// You must provide the initialization

private Map> map = ...// [1] Add your code here

public void addSong(String genre, String songTitle) {

// You must implement this method

// [2] Add your code here

}

public String getGenreOfSong(String songTitle) {

// You must implement this method

// [3] Add your code here

}

}

The following are map methods that you may find helpful for this problem:

  • Vget(Objectkey) - Returns the value to which this map maps the specified key.
  • Vput(Kkey,Vvalue) - Associates the specified value with the specified key in this map.
  • SetkeySet() - Returns a set view of the keys contained in this map.

The following are set methods that you may find helpful for this problem:

  • booleancontains(Objecto) - Returns true if this set contains the specified element.
  • booleanadd(Eo) - Adds the specified element to this set if it is not already present

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions

Question

Explain the nine components of the business model canvas.

Answered: 1 week ago