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 trialDylan Carter
4,780 Pointscant solve these errors
I get 2 errors cannot find symbol for the prompter class lines 13 and 14 " ./prompter.java:13 error cannot find symbol while (mGame.getRemainingTries > 0 { ^ symbol: variable getRemainingTries location variable mGame of type Game
./prompter.java:14: error: cannot find symbol displayProgress(); ^ symbol: method displayProgress() location: class Prompter "
My code:
----BEGIN GAME CLASS----
public class Game {
public static final int MAX_MISSES = 7;
private String mAnswer;
private String mHits;
private String mMisses;
public Game(String answer) {
mAnswer = answer;
mHits = "";
mMisses = "";
}
public boolean applyGuess(char letter) {
boolean isHit = mAnswer.indexOf(letter) >= 0;
if (isHit) {
mHits += letter;
} else {
mMisses += letter;
}
return isHit;
}
public String getCurrentProgress() {
String progress = "";
for (char letter: mAnswer.toCharArray()) {
char display = '-';
if (mHits.indexOf(letter) >= 0) {
display = letter;
}
progress += display;
}
return progress;
}
public int getRemainingTries() {
return MAX_MISSES - mMisses.length();
}
}
------BEGIN PROMPTER CLASS-----
import java.io.Console;
public class Prompter {
private Game mGame;
public Prompter(Game game) {
mGame = game;
}
public void play() {
while (mGame.getRemainingTries > 0) {
displayProgess();
promptForGuess();
}
}
public boolean promptForGuess() {
Console console = System.console();
String guessAsString = console.readLine("Enter a letter: ");
char guess = guessAsString.charAt(0);
return mGame.applyGuess(guess);
}
public void displayProgress() {
System.out.printf("You have %d attempts left to solve the puzzle: %s\n",
mGame.getRemainingTries(),
mGame.getCurrentProgress());
}
}
----BEGIN HANGMAN CLASS----
public class Hangman {
public static void main(String[] args) {
// Enter amazing code here:
Game game = new Game("treehouse");
Prompter prompter = new Prompter(game);
prompter.play();
}
}
I'm sorry I don't know how to make it show the black background code block so if you could tell me that it would be helpful as well.
1 Answer
Ken Alger
Treehouse TeacherDylan;
For the issue of displayProgress
, make sure you are spelling that correctly in your Prompter.java
code. And, I think you want to be using getRemainingTries()
, not getRemainingTries
.
Post back if you are still stuck.
Happy coding,
Ken
Dylan Carter
4,780 Pointsomg thank you, I was so focused on trying to figure out in the syntax I messed up I didn't even think it would have been a simple misspelling wow.
Ken Alger
Treehouse TeacherHappens all the time. Please it was resolved.
Ken Alger
Treehouse TeacherKen Alger
Treehouse TeacherEdited for markdown.