
|
CS
139 Algorithm Development
PA4: Word Guess
Part
A Due in Canvas by Thursday, Apr2 at 11:59PM
Part B Due in WebCAT by
Tuesday, Apr 7
at 11:59 PM
Late assignments will be
accepted in accordance with the following penalties:
- -10% on Wednesday Apr 8
- -20% on Thursday Apr 9
- -30% on Friday Apr 10
- -40% on Sunday Apr 12
- -50% on Monday Apr 13
- Not accepted afterwards
Part
C due in Canvas by Wednesday Apr 8 or one day after you have
successfully submitted to WebCAT whichever is later.
|
UPDATES:
-
4/4/2015 - Removed the requirement that you submit a test file with this assignment.
- 4/5/2015 - Cleaned up an inconsistency in the requirements. If the user guesses the same thing that they guessed before, it IS counted as a strike. However, the letter is not added to the list of userGuesses.
- 4/5/2015 - updateGuesses should return the same thing that getGuesses returns. In other words, since both Strikes and userGuesses is updated, both are returned in the formatted String.
Objectives - At the conclusion
of this assignment students will have demonstrated that they can:
- Use loops to solve problems.
- Input data from a keyboard.
- Use Java math operations.
- Properly format output to
specification.
- Divide a problem up into
different modules and methods.
- Use appropriate decision
structures to choose among several options.
- Validate data and use
default values when data does not conform to specification.
- Do everything necessary to
create, debug, and run a java
program.
- Use comments to delineate
each section of the program.
- Adhere to a Java Style Guide.
- READ
AND FOLLOW DIRECTIONS!!!!!
Background
This assignment ties together much of what we have learned so far.
In short, you are to implement the support functions for a Word Guess game (like Hangman).
In this game, a player is presented with a series of blanks representing a hidden word. The player guesses letters; if the letter is in the word, the word is updated to reveal the letter of that guess filled into the correct spots in the word. If the player does not guess a letter in the word, he/she receives a strike. If the player guesses the word (reveals the last letter) in fewer than 6 guesses they win. If it takes 6 guesses or longer, they lose. In this variant, if a player guesses a letter that they have already guessed, it IS counted as a strike.
Requirements
PART
A - This assignment will require that you manipulate Strings. Part A will give you some practice in that by doing a number of CodingBat exercises to become more familiar with String methods.
PART
B - Submitted to webcat. WebCAT
will be made available no later than Sunday morning Mar 22. NOTE: Each
of your methods will be tested separately. Your methods must conform to
the design requirements below. You will also need to submit your own
test file to WebCAT.
Start with the following files:
The latter three files are a driver that will let you test the scoring interactively. You will still need to provide your own JUnit tests, however, when submitting your program to WebCAT. (NOTE: This PA will be easier if you test incrementatlly---as you are building each method---rather than trying to test with the Driver.)
Don't forget: All your files must conform to the CS 139 Style Guide including documentation. The tester, WordGuess_Test must also conform to all standards.
For this assignment, pay special attention to the indentation rules and writing class and method documentation. All blocks of code (even if one line) should be surrounded by curly braces. You are also required to fill in the method documentation in your WordGuess.java class and WordGuess_Test. Methods are described below.
Some Definitions
theWord - The word from the dictionary. It should be preserved throughout play.
userWord - The word that represents the progress the user is making on the word.
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.
guesses - The list of characters that the user has guessed that are not in the Word.
Required Methods
These are called directly by the WordGuessDriver.java. You may add additional methods as well.
- public int getStrikes()
- getStrikes returns the value of the number of strikes for this player.
- public String getGuesses()
- getUserGuesses returns a String that is in the form "Strikes: %d\tGuesses: %s", where Strikes is the number of bad guesses and Guesses is the list of guesses separated by spaces.
- For example, if there were 3 strikes (bad guesses) and the userGuesses was "bcd" this method would return "Strikes: 3 Guesses: b c d"
- public String getTheWord()
- getTheWord returns the value of the dictionary word (which should not change throughout the game)
- publicString getUserWord()
- getUserWord returns a String that is the userWord with spaces between each letter and _.
- For example, if the userWord is "fe___' this method would return "f e _ _ _". Note that there is no space before the 'f' and after the last '_'.
- public boolean isOut()
- isOut returns true if the User has 6 strikes and false otherwise
- public boolean isWordComplete()
- isWordComplete returns true if the user has guessed all of the letters and false otherwise.
- public String makeUserWord()
- makeUserWord takes in the word the player is guessing and returns a word of the proper length set to "_" values that indicate a letter has not yet been guessed.
- For example, if the word were "dog", this method updates the user word to "_ _ _". NOTE: This method is called by the constructor.
- public boolean isInWord(char guess)
- isInWord takes in the user guess and the word, and returns true if the guess is in the word, false otherwise.
- For example, if the guess were 'x' and the word "xylophone" this method would return true.
- public String updateGuesses(char guess)
- updateGuesses updates the list of guesses with the current guess. The update should only add the guess if it does not already exist in the list and must put the guess in the correct alphabetical order.
- For example, if the userGuesses was "bdet" and guess was 'f', userGuesses would become "bdeft". Update Guesses will be used to list all guesses and not just the wrong ones.
-
- Update guesses should also update strikes if the character is not in the word or the character is in the word and the user has already guessed the letter. For example, if the word is "fetch" and the user guesses 'e' and userGuesses includes "bdeft" then strikes should increase by one. This method should return the same thing the getGuesses returns.
- public String updateUserWord(char guess)
- updateUserWord changes the userWord with all occurrences of _ corresponding to the current guess with a corresponding match in word replaced with the guess.
- For example, if the word was fetch and the user word was f____ and the user guessed 'e', the return string would be f e _ _ _. This method both updates the userWord in the object and returns the new version.
Hints
- Test each method as you are building it to make sure that it is working correctly. The Test file and the build of the WordGuess file should go hand in hand. Build test cases, then build the code, then test the code. Only when everything is ready should you try to run the driver.
- Some of the update methods (updateGuesses and updateUserWord) can be done in several ways. Think through the problem carefully before you begin to code. These are the two hardest methods. Leave them for last when you know everything else is working (since you might be using some of them in these methods).
- Use chapter 9 as a reference to String methods that you may not have used before.
- The "seed" value in the driver is intended to control the words that are displayed. With a seed of 123456789, the Dictionary Random object will return bookkeeper as the first word. You can display the words at any time if you want to see what the word is for testing purposes when you are ready to do your System test. You can call the Driver and pass in a different number to make the game truly random or change the Dictionary class so that it uses the system time (default constructor).
Deliverables
Put WordGuess.java and WordGuess_Test.java in a zip file, and submit via Web-CAT.
Submit WordGuess.java to Web-CAT. Do not include any other java or class files in your zip file.
Part C Reflection - graded as
a regular homework assignment. There will be separate Canvas
Assignments
for this.
You will write a reflection
document for this assignment which will
let you consider the process of building this program. It will also
contain a place to critique this assignment for this class.
Honor Code
This is an individual
programming assignment. This assignment should be viewed as a take home
exam. Your work on the assignment and your submission must conform to
the JMU Honor
Code. Authorized help is limited
to the classroom handouts, lab material, the TAs for any CS139, our
graduate student and the professor. Copying work from another student
or the Internet is an honor code violation, which will result in a zero
on the assignment and
possibly further sanctions. You may use the internet to search for
help, but each site that you use hould be acknowledged in the Reference
section of the code documentation.
Your work on this assignment is
subject to review by MOSS
which is a plagiarism detection tool for programs. Submission to WebCAT
constitutes your submission of work for academic credit and your
agreement that your work may be submitted to MOSS.