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

Karaoke Machine Code problem

Karaoke Machine Code

package com.teamtreehouse; import com.teamtreehoue.model.SongBook; import com.teamtreehouse.model.Song; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.IOException;

import java.util.HashMap; import java.util.Map;

public class KaraokeMachine{

private SongBook mSongBook; private BufferedReader mReader; private Map<String, String> mMenu;

public KaraokeMachine(SongBook songBook){ mSongBook = songBook; mReader = new BufferedReader(new InputStreamReader(System.in)); mMenu = new HashMap<String, String>(); mMenu.put("add", "Add a new Song to Song Book"); mMenu.put("quit", "Give up. Exit the program"); }

private String promptAction() throws IOException{ System.out.printf("There are %d songs available. Your options are", mSongBook.songCount());

for (Map.Entry <String, String> option : mMenu.entrySet()){
  System.out.print("%s - %s", option.getKey(), option.getValue());
}

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();
        mSongBook.addSong(song);
        System.out.println("Wait");
        break;
      case "quit":
        System.out.printf("Unknown Choices  %s. Try again %n%n%n", choice);

    }
  } catch(IOException ioe) {
    System.out.println("Problem with input");
    ioe.printStackTrace();
  }
}while(!choice.equals("quit"));

}

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

}

}

The error which i am not understanding right now is

/com/teamtreehouse/KaraokeMachine.java:19: error: cannot find symbol
public KaraokeMachine(SongBook songBook){
^
symbol: class SongBook
location: class KaraokeMachine
./com/teamtreehouse/KaraokeMachine.java:32: error: no suitable method found for print(String,String,String)
System.out.print("%s - %s", option.getKey(), option.getValue());
^
method PrintStream.print(boolean) is not applicable
(actual and formal argument lists differ in length)
method PrintStream.print(char) is not applicable
(actual and formal argument lists differ in length)
method PrintStream.print(int) is not applicable
(actual and formal argument lists differ in length)
method PrintStream.print(long) is not applicable
(actual and formal argument lists differ in length)
method PrintStream.print(float) is not applicable
(actual and formal argument lists differ in length)
method PrintStream.print(double) is not applicable
(actual and formal argument lists differ in length)
method PrintStream.print(char[]) is not applicable
(actual and formal argument lists differ in length)
method PrintStream.print(String) is not applicable
(actual and formal argument lists differ in length)
method PrintStream.print(Object) is not applicable
(actual and formal argument lists differ in length)
4 errors

Thanks in advance

2 Answers

Hello Bilal,

Take a look at your log:

./com/teamtreehouse/KaraokeMachine.java:32: error: no suitable method found for print(String,String,String)
System.out.print("%s - %s", option.getKey(), option.getValue());

The function System.out.print, just takes 1 parameter, but you are passing 3.

In order to print a string with format you specified, please try with System.out.format:

System.out.format("%s - %s", option.getKey(), option.getValue());

Let me know !

Thanks buddy it worked

you are welcome ! :D