Hi again,
I have to use StringBuffer on this course but also know about StringBuilder from last course.
Please do not think i am just wanting someone to do my work for me as I don't, I get a buzz out of writing methods that have not required me consulting api or this website, it's just sometimes i can look forever and get no where without someones input, which I learn massively from.
I have a error
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 1
at java.lang.StringBuffer.setCharAt(StringBuffer.java :211)
at tma01q3.Coder.setFeedback(Coder.java:64)
at tma01q3.Coder.updateState(Coder.java:79)
at tma01q3.Coder.turn(Coder.java:104)
at tma01q3.TestGame.main(TestGame.java:38)
which i think has something to do with this method
-
-
private void setFeedback()
-
{
-
int test = codeWord.indexOf(currentGuess);
-
System.out.println(test);
-
while(test != -1)
-
{
-
feedback.setCharAt(test, currentGuess);
-
test = codeWord.indexOf(test + 1, currentGuess);
-
-
}
-
-
-
}
-
-
Anybody see whats wrong, I am inputting a letter which is assigned to currentGuess, then I have a look at codeWord to see if it contains the letter(currentGuess) and if so setChar() of StringBuffer(feedback)