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, October 6
20 points, ~2% of total grade
Due: no later than 11 pm, Thursday, October 15
General Assignment Requirements

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.
  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.)

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 , and hangmanOutput3.txt (shortest sample, demonstrates a loss)  Use a diff tool such as the one at this website ( www.quickdiff.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.

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 14 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 170 lines long including single braces and white space, but not including the large comment at the top.

When finished turn in your Hangman.java program via Canvas.

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 your version of the PhraseBank (we will use the original) when grading so that the phrases are picked randomly.

Simply go into the PhraseBank class and comment this line (line number 86)

Collections.shuffle(phrases, new Random(RANDOM_SEED)); // comment for more random behavior

and uncomment this line (line number 87)

// Collections.shuffle(phrases); // uncomment for more random behavior

Back to the CS 312 homepage.