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 8
20 points, ~2% of total grade
Due: no later than 11 pm, Thursday, October 17
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.
For this assignment you are limited to the language features in chapters 1 through 5 of the textbook.
Description: Write a program to play Hangman. The computer 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. Look at the sample output which shows a series of games. Your program shall implement the same level of error checking. Your output must match the output shown exactly given the same secret phrases and user input.
The program will:
PhraseBookdata type has two methods for you to use,
getTopic()which returns a
Stringthat is the topic for the phrases in the file and
getNextPhrase()which returns a
Stringthat is the next secret phrase for the game. Each secret phrase contains only upper case letters and underscore characters in place of spaces.
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
toUpperCase methods. In addition String concatenation with an accumulator
pattern is used as in the ciphers program.
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 160 lines long including single braces and white space, but not including the large comment at the top.
Data File: In addition to the program you will also create a new data file and turn it in. The name of the file will be StudentData.txt. This must be a text file, not a word processing file. (Although many word processors can save files as plain text files.) The first line of the file is the topic for the secret phrases in the file. The file must include at least 100 phrases. (For example the provided file has the topic of movies.) The data file is worth 2 of the 20 points on the assignment. You cannot submit just a data file for 2/20 points. You must submit your program as well.
Extras: If you are looking to do something extra have the program print out simple text graphics to show the status of the hangman. (This may add significantly to the length of the program given the constraints of the program , chapters 1 - 5 in the book.) One suggestion for the starting gallows is this
and the completed gallows could be this:
If you do the extra portion leave it commented out so our grading scripts work. The program you turn in must match the expected output.
When finished turn in your
Hangman.java program and your StudentData.txt file using the
Checklist: Did you remember to:
Back to the CS 312 homepage.