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 Java Objects (Retired) Creating the MVP Current Progress

Jonathan Leon
Jonathan Leon
18,813 Points

Why does prompter take the paramater (Game game) and not just game ? :[

import java.io.Console;

public class Prompter {
  private Game mGame;

  public Prompter(Game game) {

    mGame = game;
  }

  public boolean promptForGuess() {

    Console console = System.console();

    String guessAsString = console.readLine("Enter a letter:  ");
    char guess = guessAsString.charAt(0);
    return mGame.applyGuess(guess);
  }
}

2 Answers

Hi Jonathan,

It is important that the method is told what type of parameter is being passed in. That's what the initial Game is doing. The second game is just a name - it is unrelated to any data type; it could just as easily be called steve.

As it is, the method knows that it is going to receive an instance of the Game class as a parameter and that instance can be referenced by using the variable name game.

I hope that makes sense!

Steve.

Jonathan Leon
Jonathan Leon
18,813 Points

That makes sense now, I compared it to

public Game(String answer) {

   mAnswer = answer;
   mHits = "";
   mMisses= "";
  }

and here too, it says Game takes an answer paramater of the String class.

Thanks for the enlightment, Could you tell me what is a Symbol when reffering to Java language?

I realize this is an old thread, but generally speaking I'd just like to mention that a symbol (in Java) is pretty much any word that's found in your code. If Java says it doesn't recognize a "symbol" then it doesn't know what the word means. Usually this happens because you haven't defined a variable.

Let's say you type

lobsterWords = "I like lobster";

but you never actually created a String called lobsterWords. You would probably get a "symbol" error because Java doesn't yet know what lobsterWords is. It could be an int or a String or a keyword. Java doesn't know until you define the variable.