CS139 Algorithm Development


Software Requirements Specification

Programming Assignment 4

Word Guess

Due Friday, November12 by 5pm


Introduction

Purpose: This application will play a game similar to the child's game, "Hangman". 

Objectives - At the conclusion of this exercise the student will demonstrate that they can:

Deadlines

Prerequisites

You have covered the material in Chapter 2, 3, 4, and 5 of Gaddis.  You will want to reference Chapter 10 on String methods as you work the PA.

Starter Files

Dictionary.java - This class will provide the game words.  Documentation for the Dictionary class is found here.
WordGuessDriver.java - This class will create the WordGuess game and intiate play. You must not change this file as it takes caare of bringing in the Random starter. Submit will use this to control the words for test runs.
WordGuess.java - This is the class into which you will place most of your code. We have given you a starter which builds the dictionary.
Words.csv - This is a list of words that work with the Dictionary.java class. Download this into the same directory as the rest of your work.

Program Behavior

Some terms that will be used in this description and in the Starter files. 


The Word - The word from the dictionary. It should be preserved throughout play.
Progress Word - The word that represents the progress the user is making on the word.  (It is also called the mask.)
The Guess - The letter that the user is guessing. We assume that this letter is the first letter in the String that they enter. So if they enter "peabody", we will treat it as a guess of "p".
Strikes - The number of bad guesses the user has made.
Bad Guesses - The list of characters that the user has guessed that are not in the Word.

Your application must do these things:

  1. Your program must print a Welcome message as defined below.
  2. Your program will obtain a word from the Dictionary and create the empty progress word. In the output, each character of the progress word will be separated by a space.
  3. Your program should print the number of Strikes and the bad guess list (each character is separated by a space).
  4. Your program will prompt for a letter guess from the player.
  5. If the letter is in the word, the program will update the mask with the letters that are contained in the word.
  6. If the letter is not in the word, the program will increment the strikes and add the letter to the bad guess list.
  7. After each guess, display the word with the letters guessed filled in, the number of Strikes and the list of letters guessed that are not in the word.
  8. If the player guesses the last letter in the word, announce the win If the player gets his/her 6th Strike, announce the loss.
  9. Ask the player if they want to play again. Continue steps 2 - 8 until the user says "No" in response to the play again prompt (Any variant of No will cause the program to end).
  10. Display an exit message.

Output

Sample diaglog file found here. NOTE: This does not include the spacing following each character typed by the user.

  1. Output a Welcome message: "Welcome to CS139 -- Word Guess!"
  2. Output the message, "Guess a letter to see if it's in the word.\nThe word you are trying to guess has %d letters." Substitute the length of the word for the %d.
  3. Output a blank line.
  4. Output the empty Process Word showing each letter as an underscore and separating each underline with a space. NOTE: There is no space before the first underscore and no space after the last underscore.
  5. Ouput: "Strikes: %d\tBad Guesses: %s", where the first substitution is the strike count and the second substitution is the list of bad guesses with each character separated by a space. (NOTE: There is one space between the colon and the first character and no spaces after the last character.
  6. Output a blank line, then prompt the user. "What is your guess: " NOTE: The cursor should remain on the same line as the prompt and a blank line should be printed after the user has entered their guess. 
  7. Output "YES!! %s is in the word." if the user guesses a letter in the word. Output "Nope... %s is not in the word." if the user guess is a bad guess. In either case the substitution is the user guess.
  8. Output the Process Word with the guesses filled in and each missing letter as an underscore. Each character printed should be separated by a space just as in step 4.
  9. Output the same value as step 5.
  10. Ouput a new line character and the message "Keep trying..." followed by another blank line.
  11. Repeat steps 6-10 until either the user has reached 6 bad guesses or the user has guessed the word. On their last turn, you should not print step 10.
  12. If the user makes too many guesses, output the message "Too many guesses... You lose!\nThe word was %s." where the substitution is the Dictionary word.
  13. If the user wins, output the message "\tYou WIN!!!!"
  14. Output a blank line and prompt the user to play again with the message "Do you want to play again? "
  15. Output a blank line after reading the user's response.
  16. If they answer with anything other than No, return to step 2.
  17. The final message should be: "Game over. Play again soon.\n"



Inputs and error checking

  1. Any character that a user types in is okay. In other words, even if they don't type in a letter, we will accept it as a guess. So the guess of "pop" would be interpreted as the letter "p". The number, "3" would be accepted as a guess.

  2. The only value that will end game play is "No" in any case. "N" is not an acceptable response and game play should continue.

Additional Program Requirements

  1. You must follow the structure of the starter files. There are several methods that will be useful to you. Build a Tester program that will be used to test each of the methods as you build it. You must submit this tester program as part of your program hard-copy submissions. You should have three different tests for each of the methods.

Suggested Approach

  1. This is a big problem that we have divided up in methods as a series of smaller problems. Start with the smaller problems. For example, it is crucial to be able to know if a letter is in the word.  So start with that method and test it for a letter in the word, a letter not in the word, and perhaps a letter found in different locations in the word (for String problems the first and last characters can be problematic.
  2. Do this for each of the individual methods.
  3. STOP, now design the overall game play. Decide if there are other small problems to solve that can be solved by building another method.  Build it (them) and test them.
  4. Implement the overall game play. (NOTE: At this point, you should know if each of the small problems has been solved because you have written and tested each one.

Honor Code

This work must conform to the JMU Honor Code and the specific requirements of this class. NO help may be provided by another student to another student. Authorized help is limited to your textbook, the TA’s for any CS139 section, and the professor for your section. See collaboration policy.

Grading

HINTS