Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Data Structures Efficiency! Menu UI

John Paige
John Paige
7,436 Points

KaraokeMachine.java - mix of errors

I started off with 12 errors and fixed some of them. It seems that they're all connected to the promptNewSong method.

  package com.teamtreehouse;

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

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
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 the 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: %n",
                        mSongBook.getSongCount());
      for (Map.Entry<String, String> option : mMenu.entrySet()) {
        System.out.printf("%s - %s %n",
                          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.printf("%s added!  %n%n", song);
         break;
           case "quit":
           System.out.println("Thanks for playing");
           break;
           default:
           System.out.printf("Unknown choice: '%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's 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);


     }
     }
   }                              
Picked up JAVA_TOOL_OPTIONS: -Xmx128m                                                                                                                                     
Picked up _JAVA_OPTIONS: -Xmx128m                                                                                                                                         
./com/teamtreehouse/KaraokeMachine.java:65: error: ';' expected                                                                                                           
Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m                                                                                                                                         
./com/teamtreehouse/KaraokeMachine.java:69: error: illegal start of expression                                                                                            
     private Song promptNewSong() throws IOException {                                                                                                                    
     ^                                                                                                                                                                    
./com/teamtreehouse/KaraokeMachine.java:69: error: ';' expected                                                                                                           
     private Song promptNewSong() throws IOException {                                                                                                                    
                               ^                                                                                                                                          
./com/teamtreehouse/KaraokeMachine.java:69: error: not a statement                                                                                                        
     private Song promptNewSong() throws IOException {                                                                                                                    
                                         ^                                                                                                                                
./com/teamtreehouse/KaraokeMachine.java:69: error: ';' expected                                                                                                           
     private Song promptNewSong() throws IOException {                                                                                                                    
                                                    ^                                                                                                                     
./com/teamtreehouse/KaraokeMachine.java:50: error: cannot find symbol                                                                                                     
           Song song = promptNewSong();                                                                                                                                   
                       ^                                                                                                                                                  
  symbol:   method promptNewSong()                                                                                                                                        
  location: class KaraokeMachine                                                                                                                                          
./com/teamtreehouse/KaraokeMachine.java:76: error: incompatible types: unexpected return value                                                                            
       return new Song(artist, title, videoUrl);                                                                                                                          
              ^                                                                                                                                                           
6 errors   

1 Answer

John Paige
John Paige
7,436 Points

Fixed it! It was a Scope issue. I had somehow wrote the promptNewSong method within the run block.