(Solved) : Write Program Using Eclipse 3 Parts Chapter Build Word Detective Game Game Provides Letter Q42775735 . . .

Write this program using Eclipse.

The 3 parts in this chapter build the Word Detective game. Thegame provides letters in random order and the goal is to spell asmany words as you can make from the letters. For example, from”aglle”, words include “age”, “gale”, “all”, “leg”, etc. The codefor all three parts is in the same files: WordDetective.java andTestWordDetective.java. See those files for descriptions of themethods and examples of using the methods. To run a test case,uncomment the test method call in the main method ofTestWordDetective and run the TestWordDetective program. Addadditional test cases to help verify your code is working well.

Getting Started

  • Create a project in Eclipse.
  • Download the source files WordDetective.java andTestWordDetective.java and put them into the src folder.
  • Download the .txt files and put them into the projectfolder.

Part 1

  • Write and test the loadWordSet and reorderLetters methods.

Part 2

  • Write and test the charToString, pickWordToShow, wordMatches,show, and wordSetComplete methods.

Part 3

  • Write the main method that sets up and runs the game

    import java.io.File;
    import java.io.FileNotFoundException;
    import java.util.ArrayList;
    import java.util.Random;
    import java.util.Scanner;

    public class WordDetective {

    * Finds the specified set of words in the specified file andreturns them
    * as an ArrayList. This finds the specified set in the file whichis on the
    * line number of the set. The first line and set in the file is1.
    * This returns an ArrayList with the keyword first, then : and thenfollowed
    * by the rest of the words in the set, space delimited.
    * Note: The String class indexOf method can be used to find the :.The keyword is
    * everything prior to the : and the keywords are space delimitedafter.
    * An error message to System.out should be printed and an emptylist returned
    * in the following cases:
    * A set number is not found.
    * “Error: set ” + fileSetNumber + ” not found.”
    * A set doesn’t have the : after the keyword.
    * “Error: colon (:) not found in set ” + fileSetNumber + “.”
    * Example file format:
    * about: about auto bat boat but out tab tub
    * other: her hero hot other the toe
    * their: her hire hit the their tie tier tire
    * If the set number is 2 the returned ArrayList shouldcontain:
    * [other, her, hero, hot, other, the, toe]
    * @param filename The file containing word sets.
    * @param set The number of the set, starting with 1.
    * @return The set of words, with the keyword first and later in thelist.
    * @throws FileNotFoundException
       public static ArrayList<String>loadWordSet(String filename, int set) throws FileNotFoundException{
       return null; //TODO
    * Reorders the letters in word.
    * Algorithm:
    * Copy the word into an array of characters.
    * Repeat 4 times:
    * Randomly select 2 indexes in the word array using
    * nextInt( word length) of the randGen parameter.
    * Swap the letters at the selected indexes in the word array.
    * Create a string from the array of characters.
    * @param word The letters to be reordered.
    * @param randGen A random number generator.
    * @return The letters that have been randomly ordered.
       public static String reorderLetters(String word,Random randGen) {
    return null; //TODO
    * This returns a string containing the char ch, count times.
    * For example calling with ‘a’, 5 would return:
    * “aaaaa”
    * @param ch The character to repeat.
    * @param count The number of the character.
    * @return A string with count number of ch.
       public static String charToString(char ch, int count){
    return null; //TODO
    * Returns (does not print out) a string showing the words thathave
    * been guessed and dashes (-) for the letters of the words not yetguessed.
    * Example
    * wordSet: ago, now, own, wagon
    * guessed: true, false, true, false
    * Returned string: “agon—nownn—–n”
    * @param wordSet The set of words to be guessed.
    * @param guessed Which words have been guessed.
    * @return A string showing the state of the guesses.
       public static String show(ArrayList<String>wordSet, boolean[] guessed) {
    return null; //TODO

    * Picks the first unguessed word to show.
    * Updates the guessed array indicating the selected word isshown.
    * @param wordSet The set of words.
    * @param guessed Whether a word has been guessed.
    * @return The word to show or null if all have been guessed.
       public static StringpickWordToShow(ArrayList<String> wordSet, boolean []guessed){
    return null; //TODO
    * Looks for guess in wordSet. If found then updates the guessedarray at the
    * corresponding index to true. Returns whether the guess was foundor not.
    * @param wordSet The set of words.
    * @param guessed The boolean array parallel with wordSet indicatingif a word
    * has been guessed or not.
    * @param guess The word to look for in wordSet.
    * @return Whether the guess was found in the wordSet.
       public static booleanwordMatches(ArrayList<String> wordSet, boolean []guessed,String guess) {
    return false; //TODO
    * Determines if the all the elements in the guessed array aretrue.
    * @param guessed Which words have been guessed.
    * @return true, if all the words have been guessed, falseotherwise.
       public static boolean wordSetComplete(boolean[]guessed) {
    return false; //TODO
    * This is the main program loops, prompts for user input and printsto the
    * console. For exact messages and output see the output examples inzyBooks.
    * Algorithm:
    * Initialization and Welcome
    * Note: First wordSet is the 1st line in the file. The words setsare
    * presented in the order in the file.
    * Game loop (“q” quits)
    * Load the next word set (the first time use first set) from file”sets50.txt”
    * If file not found quit with message “Error: unable to read from<filename>”,
    * with <filename> replaced with the filename.
    * Remove the first word from the word set, that is thekeyword.
    * Reorder the letters of the keyword (reorderLetters)
    * Create a boolean array, parallel to the word set, to indicatewhich words
    * have been guessed and which have not.
    * Word set loop (guessing all words or quitting exits)
    * Print out the words that have been guessed and dashes for thosethat haven’t (show).
    * Prompt for input (s to show a word and q to quit), seeexample
    * If “s” then pick word to show (pickWordToShow) and print”showing: ” + word
    * If “q” then quit
    * Otherwise, check if word matches (wordMatches) or print “not inmy list: ” + word
    * If all words are guessed (wordSetComplete) then print”Congratulations! …” and
    * increment word set, and word set loop is now complete.
    * When game loop complete (quit), then print “Thanks for playingWord Detective!”
    * @param args unused
       public static void main(String[] args) {
       Scanner input = new Scanner(System.in);
       Random randGen = new Random(876);
       final String WORD_SET_FILE = “sets50.txt”;

       System.out.println(“Welcome to WordDetective!”);

       //see algorithm in method header …
       System.out.println(“Thanks for playing WordDetective!”);

Expert Answer

Answer to Write this program using Eclipse. The 3 parts in this chapter build the Word Detective game. The game provides letters i…

Leave a Comment


We are the best freelance writing portal. Looking for online writing, editing or proofreading jobs? We have plenty of writing assignments to handle.

Quick Links

Browse Solutions

Place Order

About Us

× How can I help you?