My code is not updating write after i enter a guess can someone help me out i cant think of what would be wrong
This is my hangman class
import java.util.*;
import java.io.*;
public class Hangman {
private ArrayList<String> pool;
private ArrayList<Character> lGuess;
private String secret;
private StringBuffer hideWord;
private StringBuffer charLetters;
private StringBuffer disguise = new StringBuffer();
public Hangman(){
pool = new ArrayList<>();
lGuess = new ArrayList<>();
pool.add("easy");
pool.add("hard");
pool.add("soft");
pool.add("cheat");
pool.add("genius");
pool.add("smart");
pool.add("dumb");
pool.add("sport");
pool.add("football");
pool.add("basketball");
pool.add("baseball");
pool.add("track");
pool.add("soccer");
pool.add("computer");
pool.add("science");
pool.add("math");
pool.add("history");
pool.add("english");
pool.add("study");
pool.add("quiz");
pool.add("test");
pool.add("television");
pool.add("picture");
pool.add("teacher");
pool.add("student");
pool.add("couch");
pool.add("bed");
pool.add("chair");
pool.add("backpack");
pool.add("summer");
pool.add("graduate");
lGuess.add('a');
lGuess.add('b');
lGuess.add('c');
lGuess.add('d');
lGuess.add('e');
lGuess.add('f');
lGuess.add('g');
lGuess.add('h');
lGuess.add('i');
lGuess.add('j');
lGuess.add('k');
lGuess.add('l');
lGuess.add('m');
lGuess.add('n');
lGuess.add('o');
lGuess.add('p');
lGuess.add('q');
lGuess.add('r');
lGuess.add('s');
lGuess.add('t');
lGuess.add('u');
lGuess.add('v');
lGuess.add('w');
lGuess.add('x');
lGuess.add('y');
lGuess.add('z');
secret = pool.get((int)Math.floor(Math.random()*pool.size() )); // creates the secret word
}
public StringBuffer choseWord(String s){ // method that makes the string dashes
hideWord = new StringBuffer(s.length());
hideWord.append(s);
for(int i = 0; i < s.length(); i++){
disguise.append('-');
}
return disguise;
}
public StringBuffer letterDict(){ // method that shows the letter guess as a stringbuffer
charLetters = new StringBuffer(lGuess.size());
for(int i = 0; i < lGuess.size(); i++){
charLetters.append(lGuess.get(i));
}
return charLetters;
}
public void matchLetter(Character c){ // method that should match the guessed letter with hidden word
for(int i = 0; i < hideWord.length(); i++){
if(c == hideWord.charAt(i) ){
disguise.setCharAt(i, c);
// hideWord = hideWord.append(hideWord.substring(0, i)).append(secret.charAt(i)).append(hideWord.subst ring(i+1,secret.length()));
}
}
}
public StringBuffer eraseDict(Character c){ // method that is suppose to erase the letter dictionary when the letter is guessed
for(int i = 0; i < secret.length(); i++){
if(c == hideWord.charAt(i) && lGuess.contains(c)){
lGuess.remove(i);
}
charLetters = new StringBuffer(lGuess.size());
for(int j = 0; j < lGuess.size(); j++){
charLetters.append(lGuess.get(j));
}
}
return charLetters;
}
public Boolean gameOver(){ // boolean to say the game is over when word equals secret word
return secret.contentEquals(disguise.toString());
}
public ArrayList<String> getPool() {
return pool;
}
public ArrayList<Character> getlGuess() {
return lGuess;
}
public String getSecret() {
return secret;
}
public StringBuffer getHideWord() {
return hideWord;
}
}
This is my main class
import java.util.*;
import java.io.*;
public class Homework1 {
public static void main(String[] args) throws IOException{
Scanner input = new Scanner(System.in);
boolean valid = false;
String guess;
Hangman play = new Hangman();
System.out.println("****************************** ***");
System.out.println("*****THE WORD GUESS GAME!!!!*****");
System.out.println("****************************** ***"+"\n");
System.out.println("**********Have Fun!!!!************"+"\n");
System.out.println("The word is displayed for working purposes:");
System.out.println("Your word is: "+play.getSecret().toString()+"\n");
while(!valid){
System.out.println("Word is:"+play.choseWord(play.getSecret())+"\n");
System.out.println("Unused Letters:"+play.letterDict()+"\n");
System.out.println("Guess a letter:");
guess = input.next().toLowerCase();
Character ch = guess.charAt(0);
if(guess.length() == 0 || Character.isDigit(ch)){
System.out.println("Please enter a correct value");
continue;
}
if(guess.length() > 1){
System.out.println("Too many values, one at a time");
continue;
}
else{
if(play.getSecret().indexOf(ch) < 0) {
System.out.println("Wrong guess");
play.eraseDict(ch);
}
else{
play.matchLetter(ch);
play.eraseDict(ch);
}
if(play.gameOver()){
System.out.println("You won!!!!");
System.out.println("The word was:"+play.getSecret());
valid = true;
}
}
//System.out.print("Would you like to play again, y/n:");
}
}
}