Stuck on my Java homework -- Hangman game with StringBuilder -- help? -
*note: not asking homework. stuck.
i designing hangman class right now. apparently, need 3 stringbuilders (a) 1 display hyphens: "--------"
length of word, b) 1 display correct letters guessed: "--a--e---"
, , c) 1 opposite of b (guessed letters replaced hyphens , unguessed letters revealed). purpose of c) see if there matches during guessing.
my biggest problem can't find many practical stringbuilder examples on google, namely biggest issue can/should instantiate 3 stringbuilders in hangman class?
thanks...
i'm guessing here have hangman class works model 3 things (relevant this) is:
- gives string 1 - each character in word guess
- gives string shows correctly guessed characters in right position
- gives string shows characters have been used
these dependent on state of model be
- the word
- characters guessed
based on i'd should have 3 methods return strings , in each of methods create new stringbuilder instance. building string separate state make clear why disagree computerish.
stringbuilder more efficient way build strings using concatenation, easy use. start creating instance of it.
stringbuilder builder = new stringbuilder();
then build string appending strings or chars (or other things):
builder.append('-'); builder.append('w');
when done construct string instance stringbuilder:
string string = builder.tostring();
and end "-w" rather boring example.
Comments
Post a Comment