I am new to java and programming overall, so please bear with me. In the code below,when I run object.ValidateGuess(), I am propted 3 times "Please enter a letter to be guessed:". Why is that? Is it because I use the GetGuess() method in the if statement?? I want to use the return of that method only, not for it to run every time. thanks in advances
public char GetGuess(){
System.out.println("Please enter a letter to be guessed");
Scanner guess = new Scanner(System.in);
return guess.nextLine().charAt(0);
}
public boolean ValidateGuess(){
boolean isHit = false;
int triesLeft = MAX_TRIES;
if (mCorrectAnswer.indexOf(GetGuess()) < 0 ){
System.out.println("Your guess was incorrect");
triesLeft -= 1;
System.out.println(triesLeft);
mMisses += GetGuess();
} else if (GetGuess() == (int)GetGuess()) {
System.out.println("you have to input a letter!!!");
} else {
mHits += GetGuess();
isHit = true;
}
ifcondition involve that variable rather than call the method itself. A method call is exactly that: it calls the method.