CS 312 Assignment 6, Hangman 

Programming Assignment 6: Individual Assignment. You must complete this assignment by yourself. You cannot work with anyone else in the class or with someone outside of the class. You may not copy solutions from the world wide web. You are encouraged to get help from the instructional staff.

Placed online: Tuesday, March 1
20 points, ~2% of total grade
Due: no later than 11 pm, Thursday, March 10
General Assignment Requirements

There is an associated Perusall reading assignment for this program. Check Canvas for details,

The purpose of this assignment is to implement a program that plays the game of hangman. To do the program you will practice the following techniques.

  1. Practice creating a structured program to solve a problem.
  2. Write methods that use parameters.
  3. Write an interactive program.
  4. Practice using indefinite loops, aka while loops.
  5. Use methods from the String class and another instructor provided class.

For this assignment you are limited to the language features in chapters 1 through 5 of the textbook.

Provided Files:

  1. Hangman.java (A shell file with a main method and the header information.)
  2. PhraseBank.java (Another program that is used to read from a file and provide phrases for the game.)
  3. HangmanMovies.txt (A file with movies to use for the game.)
  4. ProSportsTeams.txt (Another file that can be used to play the game. You don't need this file to actually complete the program.)

Description: Write a program to play Hangman. The program  picks a secret phrase from a list of phrases or words.. The human player guesses letters until they reveal the entire phrase or lose due to picking too many letters that are not in the phrase.

There are three sample files: hangmanOutput1.txt, hangmanOutput2.txt , hangmanOutput3.txt (shortest sample, demonstrates a loss), and hangmanOutput4.txt (various bad inputs).  Use a diff tool such as the one at this website (www.diffchecker.com/) to ensure your program produces the correct output. Even minor differences in output will cause you to fail grading tests and lose points.

Note, the PhraseBank always picks topics in the same order. This is necessary for consistency when testing. See below for changes to your PhraseBank if you want it to pick phrases at random.

Your program must:

Approach: Divide the program into parts. Complete and test each part before moving on. Use the methods from the String class to help make your job easier. The String methods used in the sample solution are the length, charAt, contains, indexOf, substring, and toUpperCase methods.

Use a String variable to store the letters that have not been guessed, but DO NOT store the hyphens that appear between letters when displayed as a part of this String. Print the hyphens out, but do not store them in the String with the letters that have not been used yet. Failure to follow this requirement shall result in a -2 when the assignment is graded. The reason for this requirement is to separate concerns, computation and display in this case.

Divide the program up into methods to provide a structured solution. Some of the methods will be void and others will return values. You will have to make use of parameters, for loops, while loops, and if statements. By way of comparison my solution has 15 methods including the main method. No method is more than 17 total lines including the method header and the closing brace. The program is about 200 lines long including single braces and blank lines, but not including the large comment at the top.

When finished turn in your Hangman.java program via Canvas under assignment 6.


Checklist: Did you remember to:


You can create your own data files for the program. The format of these files is: topic on the first line, then the phrases or words one per line.

The PhraseBank always picks topics in the same order. This is necessary for consistency when testing. You can alter the creation of the PhraseBank so it has less predictable behavior. Change the call to the constructor for the PhraseBank to send in the boolean value true to randomize it. Note, in the final version of the program you must use the non random version of PhraseBank or you will fail all the tests,

Back to the CS 312 homepage.