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:
- Manipulate String objects to display the word in progress.
- Determine if a letter is in the word.
- Track wins by two different players playing multiple games.
- Effectively use methods to break a problem down into components,
decisions to take alternative actions and loops to repeat actions.
- Do everything necessary to create, debug, and run a java
program.
- Use comments to delineate each section of the program.
- Adhere to a Style Guide.
- READ AND FOLLOW DIRECTIONS!!!!!
Deadlines
- Submit: November 12 by 5pm into the stu submit system.
- Report: Monday Nov 15 by the beginning of class. A late penalty
will apply for each
of the 2 deadlines. If the
submit is late, the report is due the next class or lab session day
after successful submission. Programs will not be accepted after
7 days late.
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:
- Your program must print a Welcome message as defined below.
- 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.
- Your program should print the number of Strikes and the bad guess
list (each character is separated by a space).
- Your program will prompt for a letter guess from the player.
- If the letter is in the word, the program will update the mask
with the letters that are contained in the word.
- If the letter is not in the word, the program will increment the
strikes and add the letter to the bad guess list.
- 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.
- If the player guesses the last letter in the word, announce the
win If the player gets his/her 6th
Strike, announce the loss.
- 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).
- Display an exit message.
Output
Sample diaglog file found here. NOTE:
This does not include the spacing following each character typed by the
user.
- Output a Welcome message: "Welcome to
CS139 -- Word Guess!"
- 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.
- Output a blank line.
- 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.
- 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.
- 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.
- 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.
- 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.
- Output the same value as step 5.
- Ouput a new line character and the message "Keep
trying..." followed by another blank line.
- 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.
- 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.
- If the user wins, output the message "\tYou
WIN!!!!"
- Output a blank line and prompt the user to play again with the
message "Do you want to play again? "
- Output a blank line after reading the user's response.
- If they answer with anything other than No, return to step 2.
- The final message should be: "Game over.
Play again soon.\n"
Inputs and error checking
-
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.
- 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
- 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
- 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.
- Do this for each of the individual methods.
- 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.
- 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
- Your program will be evaluated both by its correctness and
conformance to the required elements.
- You will achieve a grade of 70 for a program that runs
correctly
and produces exactly the required output in the required format.
- You will achieve 10 points for submitting your Tester program.
- The remainder (20) will be based on your conformance to the
Style
and other requirements of the assignment. Review the Style
Guide before
submitting your program and the grade sheet which is produced by the
submit system.
- All grades will be based on 100 points.
- You may submit any number of times. The only one I will count
is
the one that corresponds to the hardcopy report that you turn in.
- The hardcopy that you turn in will be the formatted version
that
I will check. Make sure it has no line wraps or other spacing
issues.
- Successfully submitted programs that are late will be graded,
then the point penalty assessed for each day late.
- For
submissions after:
- Nov 12 (5 pm) - 5 points
- Nov 14 (11pm) - 15 points
- Nov 15 (11pm) - 25 points
- Nov 16 (11pm) - 35 points
- Nov 17 (11pm) - 45 points
- Nov 18 (11pm) - 100 points
HINTS
- Begin early.
This program is fairly long and you will want to work on it bit by bit.
Students run into trouble by waiting too long
to start the program.
- Understand the problem at hand. Make sure that you follow
the requirements precisely. Don't add additional "flourishes".
You will be downgraded.
- Design a top level algorithm. Don't worry as you are
designing that you might not yet know how to do input or format output.
Design as if you have those tools. You will get them before
it is due.
- Design your substeps, at least the ones you can do now.
Fill in the others as we cover material in class or you study it
in your book.
- Your top level algorithm can be used as step documentation in
your program. Start there.