Java Java Data Structures Efficiency! Queueing

Dinu Comendant
Dinu Comendant
2,908 Points

error: incompatible types: Object cannot be converted to Song

Getting this error and can't understand where the problem lies, either I'm blind or the problem is in another place in the code:

./com/teamtreehouse/ error: incompatible types: Object cannot
 be converted to Song                                                                
    Song song = mSongQueue.poll(); 

This is my code for

package com.teamtreehouse;

import com.teamtreehouse.model.Song;
import com.teamtreehouse.model.SongBook;


import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;

public class KaraokeMachine {
  private SongBook mSongBook; //accessing mSongBook from SongBook file
  private BufferedReader mReader;
  private Map<String, String> mMenu;
  private Queue mSongQueue;

  public KaraokeMachine (SongBook songBook) {
    mSongBook = songBook; //setting mSongBook as a parameter
    mReader = new BufferedReader(new InputStreamReader(; //Inputstream reads from bytes into chars, since it asks for request, its better to wrap it up in BufferedReader
    mSongQueue = new ArrayDeque<Song>();
    mMenu = new HashMap<String,String> ();
    mMenu.put("add", "Add a new song to the song book");
    mMenu.put("choose", "Choose a song to sing!");
    mMenu.put("play", "Play the next song");
    mMenu.put("quit", "Quitting the program");

  private String promptAction() throws IOException {
    System.out.printf("There are %s songs available and %d in the queue. Your options are: %n", mSongBook.getSongCount(), mSongQueue.size());
    for (Map.Entry<String, String> option : mMenu.entrySet()) {
      System.out.printf("%s - %s %n",
    System.out.print("What do you want to do:  ");
    String choice = mReader.readLine();
    return choice.trim().toLowerCase();

  public void run () {
    String choice = "";
    do {
      try {
        choice = promptAction();
        switch (choice) {
          case "add":
          Song song = promptNewSong();
          System.out.printf("%s added! %n%n", song);
          case "choose":
            String artist = promptArtist();
            Song artistSong = promptSongForArtist(artist);
            System.out.printf("You chose: %s %n", artistSong);
          case "play":
          case "quit":
            System.out.println("Thanks for using the program");
          default :
            System.out.printf("Unknown choice:  '%s'. Try again. %n%n%n",
      } catch (IOException ioe) {
        System.out.println("Problem with input");
    } while (!choice.equals("quit"));

  private Song promptNewSong() throws IOException {
    System.out.print("Enter artist's name:  ");
    String artist = mReader.readLine();
    System.out.print("Enter the title of the song:  ");
    String title = mReader.readLine();
    System.out.print("Enter the videoURL:  ");
    String videoUrl = mReader.readLine();
    return new Song(artist, title, videoUrl);

  private String promptArtist() throws IOException {
    System.out.println("Available artists: ");
    List<String> artists = new ArrayList<>(mSongBook.getArtists());
    int index = promptForIndex(artists);
    return artists.get(index);

  private Song promptSongForArtist (String artist) throws IOException {
    List<Song> songs = mSongBook.getSongsForArtist(artist);
    List<String> songTitles = new ArrayList<>();
    for (Song song : songs) {
    System.out.printf("Available songs for %s:  %n", artist);
    int index = promptForIndex(songTitles);
    return songs.get(index);

  private int promptForIndex (List<String> options) throws IOException {
    int counter = 1;
    for (String option : options) {
      System.out.printf("%d ) %s %n", counter, option);
      counter ++;
    System.out.println("Your choice: ");
    String optionAsString = mReader.readLine();
    int choice = Integer.parseInt(optionAsString.trim());
    return choice -1;

  public void playNext() {
    Song song = mSongQueue.poll();
    if (song == null) {
      System.out.println("Sorry, there are no songs in the queue" + 
                         "Use the button CHOOSE to add a song");
    } else {
      System.out.printf("%n%n%n Open %s to hear %s by %s %n%n%n",