Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Matthew Lee
Matthew Lee
6,715 Points

In the Karaoke Machine Refactoring updating case "choose" question!!

case "choose":
                    String singerName = promptSongForArtist();
                    String artist = promptArtist();
                    Song artistSong = promptSongForArtist(artist);
                    SongRequest songRequest = new SongRequest(singerName, artistSong);
                    if (mSongQueue.contains(songRequest)) {
                        System.out.printf("%n%n Whoops %s already requested %s! %n",
                                singerName,        ///shouldnt it be previous singername who requested the song?
                                artistSong
                                );
                        break;
                    }
                    mSongQueue.add(songRequest);
                    System.out.printf("You chose %s's %s. %n", artist, artistSong);
                    break;

in the if statement, we print out "whoops %s already requested %s" where the first %s is the singerName and the second %s is the artistSong.

However, wouldn't the singerName have the value of the singer who is trying to add the song again?

How would I retrieve the singerName who saved the song before?

The singerName and artistSong would come from the songRequest of the mSongQueue.contains(songRequest) which would be the previous singerName who originally added the song.

1 Answer

Matthew Lee
Matthew Lee
6,715 Points

AJ Longstreet Thanks for answering. I'm still a little confused.

if(mySongQueue.contains(songRequest) -> here we are passing in songRequest from the line above, which passes in the singerName passed in by the current user....

Is this not true?

Thanks