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 trialJordan Bester
4,752 PointsGame.Java.33: error reached end of file while parsing? please help
public class Game { 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; }
Jordan Bester
4,752 PointsHere is my hangman code:
public class Hangman {
public static void main(String[] args) {
// Enter amazing code here:
Game game = new Game("treehouse");
Prompter prompter = new Prompter(game);
prompter.displayProgress();
boolean isHit = prompter.prompterForGuess();
if (isHit) {
System.out.println("We got a hit");
} else {
System.out.println("Whoops that is a miss");
}
prompter.displayProgress();
}
}
1 Answer
Jeremy Hill
29,567 PointsYou may need to add or subtract a curly brace. Check to make sure that you have a closing curly brace for your methods and class.
Amanda Oliver
624 Pointsadding or subtracting a bracket is not working. It says the same error: "reached end of file while parsing" my code looks identical to Craig's. What could I be doing wrong? https://w.trhou.se/bmc1x7u7fk
Jordan Bester
4,752 PointsJordan Bester
4,752 Pointshere is my prompter code:
import java.io.Console;
public class Prompter { private Game mGame;
public Prompter (Game game) { mGame = game; }
public boolean prompterForGuess() { Console console = System.console(); String guessAsString = console.readLine(" Enter a letter my dude: "); char guess = guessAsString.charAt(0); return mGame.applyGuess(guess); }
public void displayProgress() { System.out.printf("Try to solve: %s\n", mGame.getCurrentProgress()); } }