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 trialKHARAK SINGH
1,061 Pointswhat is Prompter prompter doing in this code?
public class Hangman {
public static void main(String[] args) {
// Enter amazing code here:
Game game = new Game("treehouse");
Prompter prompter = new Prompter(game);
boolean isHit = prompter.promptForGuess();
if (isHit) {
System.out.println("We got a hit.");
} else {
System.out.println("Whoops that was a miss.");
}
}
}
2 Answers
Gleb Sklyr
17,492 PointsWhen you create a Prompter object you can now use the methods in the class. In this case, if you go to the Prompter class definition, you will find the promptForGuess() method that uses the Game object that was used as an argument in the declaration of the Prompter to prompt for a guess. It returns a boolean that will be set to True if the guess hits "treehouse" which was the argument in creating the Game object used in turn in creating the Prompter object.
ibrahim Warsame
7,803 PointsBasically you are creating a reference variable that points to an object in the heap, and you are basing in the game object as a argument.