/**
 * CS139 - Programming Fundamentals
 * Department of Computer Science
 * James Madison University
 * @version Spring 2016
 */

PA4: Hangman

Instructions

For this assignment you will implement six methods to support the development of "Word Guess" games like Hangman.

The following five files represent a complete command-line hangman program:

When Hangman.java is executed, 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 or she receives a strike. If the player guesses the word (reveals the last letter) in fewer than 6 guesses, they win. If it takes more than 6 guesses, they lose. In this assignment, if a player guesses a letter that they have already guessed, it is not counted as a strike. Sample output from one such game can be found here.

The last three files are provided only as an example, and they will not be used in grading your assignment. You should build and test WordGuess.java incrementally -- as you are writing each method -- rather than trying to test with Hangman.java all at once.

Required Methods for WordGuess.java

The following terms will be used consistently throughout the method descriptions below.

theWord
The current word to guess. It will be preserved throughout play.
userWord
A pattern that represents the progress the user is making on the word.
guess
The letter that the user is guessing.
strikes
The number of bad guesses the user has made.
guesses
A list of characters that the user has guessed.

Method Specifications

public static String makeUserWord(String theWord)
Takes the word the player is trying to guess and generates a pattern of '*' values to represent letters that have not yet been guessed. For example, if the word were "dog" this method would return "***".
public static boolean isInWord(char guess, String theWord)
Returns true if the guessed character is in the word, false otherwise. For example, if the guess were 'x' and the word were "xylophone" this method would return true.
public static String updateUserWord(char guess, String userWord, String theWord)
Returns a userWord with all occurrences of '*' corresponding to the current guess replaced with that guess. For example, if the word was "fetch" and the user word was "****h" and the user guessed 'e', the return string would be "*e**h".
public static String updateGuesses(String guesses, char guess)
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. The new guess must be placed at the end of the existing list of guesses. For example, if guesses were "tabg" and the current guess were 'f', this method would return "tabgf".
public static String displayUserWord(String userWord)
Returns a String that is the userWord with spaces between each letter and each '*' replaced with an '_'. 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 static String displayGuesses(int strikes, String guesses)
Returns a String in the form "Strikes: %d\tGuesses: %s", with the list of guesses separated by spaces. For example, if there were 3 strikes and guesses were "bcd", this method would return "Strikes: 3\tGuesses: b c d".

Part A

Before the deadline for Part A you should read this document carefully. Once you have a clear understanding of the expectations for this assignment, complete the readiness quiz in Canvas. The grading for this quiz will be all or nothing: your score on the quiz will be 0 if you miss any questions. If you do not successfully complete Part A, you cannot receive any credit for Part B.

Part B

Combine your WordGuess.java and WordGuessTest.java into a zip file, and submit via Web-CAT. Do not include any other files in your zip archive. WordGuess.java must conform to the CS 139 Style Guide.

Your submission will be graded using the following criteria:

Points
Web-CAT Correctness/Testing50
Web-CAT Checkstyle Tests20
Style and Code Organization20

If Web-CAT deducts any points for correctness/testing, you will receive at most 25/50 on that component of the score.

Once again there will be a penalty for excessive submissions. The first 10 submissions are free. Each submission beyond 10 will result in a .5 reduction in the final score.

Honor Code

This assignment must be completed individually. Your submission must conform to the JMU Honor Code. Authorized help is limited to general discussion on Piazza, the lab assistants assigned to CS 139, and the instructor. Copying work from another student or the Internet is an honor code violation and will be grounds for a reduced or failing grade in the course.

Acknowledgments

This assignment was originally developed by Chris Mayfield, Nancy Harris and others.