import java.io.*; import java.util.*; public class TextTwistSkeleton { public static void main(String[] args) { /* declare the following * Scanner for user input * Random for a random number generator (needed to pick a random word from the dictionary) * score (an int) initialized to 0 - this is the user's score * rightGuesses(an int) initialized to 0 - this is the number of correct words so far guessed, needed for the tried array * 2 String arrays, words and tried, whose sizes are both 30113 * words will store the list of dictionary words * tried will store all correct words guessed so far, this is used so that the user can't keep guessing the same word * guess - a String of the user's current guess * word - a String of the randomly selected 6-letter word from the dictionary * letters - a char array of size 6 to store the 6 letters in the randomly selected word */ // Instantiate the three arrays // Instantiate the Scanner words=loadWords(); // this method loads the words from a disk file, this is already implemented word=selectWord(words); // get a random word from the words array, you will have to implement this method letters=getLetters(word); // this will return the 6 letters of the word in sorted order printLetters(letters); // this will output the 6 letters so that the user can see them, you will have to implement this guess=in.next().toLowerCase(); // get the user's next guess while(!guess.equals("quit")) // if its not "quit", the game continues { if(isLegal(guess,letters)) // the input word is a legal word (3-6 letters where the letters are all part of word) { if(notTried(guess,rightGuesses,tried)) // if input word has not been tried yet { if(trueWord(guess,words)) // if the word is in the dictionary { // add to score the amount that guess is worth (scoring is listed below) tried[rightGuesses]=guess; // put guess on the tried list so that the user cannot repeat it rightGuesses++; // tell the user that the word is correct and show them their current score } else // output that this word is not a dictionary word } else // output that this word has already been guessed } else // output that their guess was illegal (wrong size or wrong letters) printLetters(letters); // repeat these steps to get the next guess guess=in.next().toLowerCase(); } // the user has typed "quit", output their final score and what the original word was } // scoring will work like this: // a 3-letter word is worth 3 points // a 4-letter word is worth 5 points // a 5-letter word is worth 9 points // a 6-letter word is worth 12 points // you can use a nested-if-else statement above where it says "add to score the amount that guess is worth", or you can use // a switch statement, or you could do score=score+getWorth(guess); and write a getWorth method that will return an int // implement the following methods public static String selectWord(String[] words) { // instantiate a random number generator // using a do-while loop: get a random word from words until the random word has a length of 6 // you could do tempWord=words[g.nextInt(30113)]; and then test to see if tempWord.length()==6 // return tempWord } public static char[] getLetters(String word) // this method creates an array of 6 chars, one per letter of word { char[] letters=new char[6]; // iterate for i from 0 to 5 and take each char of word and put it into letters[i] sort(letters); // already implemented return letters; } // this method will sort the array of letters in ascending order, note that this is not a very efficient sort but since public static void sort(char[] letters) // we are only sorting 6 things, it will do { char temp; for(int i=0;i<5;i++) for(int j=i+1;j<6&&i!=j;j++) if(letters[i]>letters[j]) { temp=letters[i]; letters[i]=letters[j]; letters[j]=temp; } } public static void printLetters(char[] letters) { // use a for loop to print (as in System.out.print) the 6 letters in a row and then end the line } public static boolean isLegal(String word, char[] letters) { // this method will test to see if word was legal which means that word is between 3 and 6 characters and that each character // of word is found in the letters array // first test word's length, if < 3 or > 6, return false, otherwise continue with this method // use a for loop to iterate through the characters in word (that is, for(i=0;i