See the How To pages for details on creating projects, files, and so on. The pages here describe in broad strokes what this assignment is about.
Hangman
Hangman is a traditional children’s game, typically played with words. It’s possible, however, to play Category Hangman — rather than guessing words the player might guess names of cities, or athletes, or fictional characters, or Duke professors, or top forty song titles — the list is endless. You’ll be writing a program to play a “guess a word letter-by-letter” version of hangman as shown below. You’ll also be doing some statistical analysis of the words used in the Hangman game. This assignment is very similar to the hangman assignment in CompSci 100, but with the addition of an analytical part. Goals
- Understand how classes call and interact in Java.
- Gain familiarity with strings, arrays, loops, and printing in Java.
- Practice a forensic/scientific/analytical approach to data that we’ll build on during the semester.
- Understand the differences between primitive types and objects/classes.
Overview
Part 1a: Statistical/Forensic Analysis
You’re given a class HangmanFileLoader.java which you use in the game to get a word the user will guess. For this first part of the assignment you’ll add to code started for you in HangmanStats.java to answer the question below.
We want you to estimate the number of different words there are of 4, 5, 6, and so on up to 20 letters long. For example, to estimate the number of 6-letter words you can repeatedly call HangmanFileLoader.getRandomWord(6), and add the returned word to a set. The size of the set is an estimate of the number of words of length 6. See the How To for more details.
Part 1b: Your Own Question
Pose your own question about the words and the code that generates the random words of a specific length in HangmanFileLoader. Write code to answer your question and include the data in the analytical write-up you turn in. You could, for example, wonder:
- On average, how many calls are needed before some word is returned that was previously returned?
Remember, to calculate an average you will need to run your code multiple times to collect data. Any question you write is fine, but you must write code to answer the question. You’re welcome to come up with ‘extra’ questions (up to three) that you don’t write code for, but which you’d like to be able to answer/write code to answer. Include all questions in your analytic write-up.
WriteUp.pdf
In your WriteUp.pdf you’ll explain your methodology for Part 1a and 1b. Include your questions and data to support your conclusions. You’re welcome to create and use charts, tables, etc.
You should also include the code you wrote to create your statistical analysis and explain how you ran the code to get the data you used in your analysis.
Part 2: Hangman Game
Write a program to play a console-based, word-oriented game of hangman. The user should be allowed to specify the number of letters in the word and the number of misses until the game is lost (see the sample runs below for details). The program should be reasonably robust in the face of faulty input from the user, though don’t go overboard in writing code to protect against bad input. One detail you should consider is duplicate letters. If you have already guessed ‘e’ and then you guess ‘e’ again, that should not cost you a guess. Details and guidelines of how to organize the program, including the methods you should write, are described in the How To pages.
Here’s a sample run of Hangman. You do not need to follow the format exactly, but you should include with each turn the player takes the following information:
- Secret word, showing blanks and correct guesses.
- Number of misses left until hanging occurs.
- Letters that have been guessed incorrectly.
In the run below the user input is in italics, the other text is printed by the program.
# How many letters in guess word: 8 # How many guesses to hanging: 7 _ _ _ _ _ _ _ _ misses left: 7 guesses so far: # What letter do you want to guess: e no e _ _ _ _ _ _ _ _ misses left: 6 guesses so far: e # What letter do you want to guess: a no a _ _ _ _ _ _ _ _ misses left: 5 guesses so far: a e # What letter do you want to guess: o no o _ _ _ _ _ _ _ _ misses left: 4 guesses so far: a e o # What letter do you want to guess: u no u _ _ _ _ _ _ _ _ misses left: 3 guesses so far: a u e o # What letter do you want to guess: i _ _ _ i _ _ i _ misses left: 3 guesses so far: a u e o # What letter do you want to guess: s no s _ _ _ i _ _ i _ misses left: 2 guesses so far: a e o s u # What letter do you want to guess: t no t _ _ _ i _ _ i _ misses left: 1 guesses so far: a e o s u t # What letter do you want to guess: r _ _ r i _ _ i _ misses left: 1 guesses so far: a e o s u t # What letter do you want to guess: n no n you are hung, the secret word is cyrillic
Submit your code, README.txt, and WriteUp.pdf using the submit name hangman.
Grading
- Analytical write-up: 4 points
- Game quality: 6 points
- Does the code track used letters, is the output reasonable
- For this assignment robustness in the face of user errors is NOT important. Don’t worry about writing code, for example, to make sure the user enters a number if you ask for the number of letters in the to-be-guessed word.
Extra Credit
Words are kind of old, offer the user the choice of playing hangman in more than one category, reading “words” from files you provide, e.g., instead of words use actors, books, and so on.