This is sample of my code. I need be able to have a cumulative score after the user plays x number of times. But keep getting same answer.
import java.util.Scanner; public class Hangman { public static void main(String[] args) { System.out.println("Welcome to Hangman... v1.0 - Designed Ashley Bwanya"); initGame(); } public static void initGame() { int errors = 0; int cumScore = 0,score; String word; String displayHidden = ""; String used = ""; Game myWord = new Game(); char guess; word = myWord.getWord(); for (int i = 0; i < word.length(); i++) { displayHidden += "*"; } StringBuilder guessedWord = new StringBuilder(word); StringBuilder test = new StringBuilder(displayHidden); System.out.println("This is the secret word you have to guess: \n"); System.out.println(test+ "\n"); while(guessedWord.toString().equals(test.toString( )) == false && errors < 5) { char[] lettersGuessed = new char[10] ; System.out.print("Guess Letter: "); Scanner scan = new Scanner(System.in); guess = scan.next().charAt(0); //System.out.println("Letters Already Used: "+ lettersGuessed[0]); for(int i = 0; i < guessedWord.length(); i++){ //check if letter has been guessed if(guessedWord.charAt(i) == guess) { test.setCharAt(i, guess); System.out.println(test); } } if(word.indexOf(guess) == -1 ) //if letter not in secret then errors goes up by 1 and while loop continues { errors++; } if(guessedWord.toString().equals(test.toString( )) == true) { score = (5 - errors); cumScore += score; System.out.println("You win !!!"); System.out.println("Your cumlative score is: " + cumScore); initGame(); } if(errors == 5) { score = (5 - errors); String name; Scanner input = new Scanner(System.in); System.out.println("You lose !!!"); System.out.println("Your score is: " + score); System.out.print("Please enter your name: "); name = input.nextLine(); myWord.setSaveScore(name, score); } } } }