I am trying to call the methods from my subclass hangmanwords in hangman, my main class. This is the code:
public class hangManWords {
//declares words
String [] words = { "Highschool", "Government", "Continents", "Professors", "Programmer", "Dealership", "Controller", "Motorcycle", "Lightsaber"};
public void randomizeWords(String [] words) {
//randomize the words
for (int i = words.length - 1; i > 0; i--) {
//generate a random index
int j = (int)(Math.random() * (i + 1));
//swaps list i with list j
String temp = words[i];
words[i] = words[j];
words[j] = temp;
}
}
public String getNextWord (String [] words) { //gets the next random word
for (int i = 0; i < words.length; i++) {
if (words[i] == null) {
continue;
}
String temp = words[i];
words[i] = null;
return temp;
}
return null;
}
}
Here is the part in my main, where I'm trying to use it:
randomizeWords(words); //randomly generates a word from the word list
//players first word
guessThisWord = getNextWord(words);
guessThisWord = hideWord(guessThisWord, originalWord);//hides the word with _