Java Java Data Structures Efficiency! Queueing

status 401
status 401
14,144 Points

questions about the <Song> object that we pass to queue and to other interfaces.

Hi, in this examples:

 private Queue<Song> mSongQueue;

why we pass <Song> to the mSongQueue?, i understand that mSongQueue is of type "Song" but im not 100% sure that im right about this. We pass <Song> because in the Song class contains all the information, properites, methods and etc about the artist,title and videoUrl?

Song artistSong = promptSongForArtist(artist);

same goes for this example? why artistSong is of type Song?

and here

public SongBook()
  {
    mSongs = new ArrayList<Song>();
  }

if for some reason we wanted to use the properites of SongBook like we did in the KaraokeMachine constructor i understand that we need to create a new instance aka access point to the class but in interfaces i just want a clarification..

Tonnie Fanadez Brendan Whiting

If u can clear this up i will appreciate this.

1 Answer

Tonnie Fanadez
Tonnie Fanadez
UX Design Techdegree Graduate 21,196 Points

Hello noob developer

In this context we are using Queue to store or to carry song object inside it. The Queue enables us to add new songs, get the total number of songs in the queue or retrieve what the first song on the Queue.

mSongs = new ArrayList<Song>

You don't even have to specify the Song Object between the diamond brackets of the ArrayList since it is already defined on the Queue

Properties and Method of Song Class are not important here.