HOMEWORK: We're working on a hangman program. I have the following method:
public char[] selectWord()
{
String[] hangmanWords = new String[50] { "time", "person", "year", "way", "day", "thing", "man", "world", "life", "hand", "part", "child", "eye", "woman", "place", "work", "week", "case", "point", "government", "company", "number", "group", "problem", "fact", "good", "new", "first", "last", "long", "great", "little", "own", "other", "old", "right", "big", "high", "different", "small", "large", "next", "early", "young", "important", "few", "public", "bad", "same", "able" };
Random wordIndex = new Random();
int randomIndex = wordIndex.Next(0, 49);
wordToGuess = hangmanWords[randomIndex].ToUpper();
char[] wordToGuessArray = wordToGuess.ToCharArray(); // convert word to array of letters
return wordToGuessArray;
}
I would like to define a constructor for wordToGuessArray. Ideally I want the selectWord() method to set the wordToGuessArray parameter. However, I won't know the variable array length until after I run this method and I can't create a constructor without explicitly defining char[x]. This question has the array length set in main. Mine cannot due to requirements restrictions in the assignment. So where would this selectWord() method need to live in order to properly set my variable?
I'm having a hard time picturing a workable program flow for that.