Reminder: - Illinois State University …  · Web viewAll programming assignments in this course...

4
Program 3 Class Design, Decision Structures, and Loops Pseudocode Due Date: Thursday, October 1, noon. (This part is worth 15 homework points.) Program Due Date: Thursday, October 8, noon. (This program is worth 50 programming points.) Reminder: All programming assignments in this course are individual assignments. You are allowed to discuss the program logic with and/or get help from your lecture instructor only! The Problem: Consider a class (call it Hangman.java) that could be used to play a game of hangman (Sorry about the name. While the name and picture are questionable in taste, they are still in use today. For more info, check out the Hangman entry on Wikipedia .) The class has the following attributes: The secret word. The disguised word, in which each unknown letter in the secret word is replaced with a question mark (?). For example, if the secret word is abracadabra and the letters a, b, and e have been guessed, the disguised word would be ab?a? a?ab?a. The number of guesses made. The number of incorrect guesses. It has the following methods: makeGuess(c) guesses that character c is in the word. getDisguisedWord returns a string containing correctly guessed letters in their correct positions and unknown letters replaced with ?. getSecretWord returns the secret word. getGuessCount returns the number of guesses made.

Transcript of Reminder: - Illinois State University …  · Web viewAll programming assignments in this course...

Page 1: Reminder: - Illinois State University …  · Web viewAll programming assignments in this course are individual assignments. ... makeGuess(c) guesses that character c is in the word.

Program 3Class Design, Decision Structures, and Loops

Pseudocode Due Date: Thursday, October 1, noon. (This part is worth 15 homework points.)Program Due Date: Thursday, October 8, noon. (This program is worth 50 programming points.)

Reminder:All programming assignments in this course are individual assignments. You are allowed to discuss the program logic with and/or get help from your lecture instructor only!

The Problem:

Consider a class (call it Hangman.java) that could be used to play a game of hangman (Sorry about the name. While the name and picture are questionable in taste, they are still in use today. For more info, check out the Hangman entry on Wikipedia.)

The class has the following attributes:

The secret word. The disguised word, in which each unknown letter in the secret word is replaced with a

question mark (?). For example, if the secret word is abracadabra and the letters a, b, and e have been guessed, the disguised word would be ab?a?a?ab?a.

The number of guesses made. The number of incorrect guesses.

It has the following methods:

makeGuess(c) guesses that character c is in the word. getDisguisedWord returns a string containing correctly guessed letters in their correct

positions and unknown letters replaced with ?. getSecretWord returns the secret word. getGuessCount returns the number of guesses made. isFound returns true if the hidden word has been discovered. initialize performs initialization of the attributes. createDisguisedWord(word) returns word with all its chars replaced with ? playGame plays the Hangman game!

The following shows the method headers (i.e., the interfaces) of the class. Each one shows the precondition and postcondition.

public void makeGuess(Character c)Precondition: The character is one of the 26 alpha characters.Postcondition: The number of guesses and incorrect guesses is updated, the disguised word is updated.

public String getDisguisedWord()

Page 2: Reminder: - Illinois State University …  · Web viewAll programming assignments in this course are individual assignments. ... makeGuess(c) guesses that character c is in the word.

Precondition: none.Postcondition: The disguised string was returned.

public String getSecretWord()Precondition: none.Postcondition: The secret word was returned.

public int getGuessCount()Precondition: none.Postcondition: The number of correct guesses was returned.

public boolean isFound()Precondition: none.Postcondition: True was returned if the disguised word has become the secret word.

public void initialize(String word)Precondition: none.Postcondition: All of the attributes were initialized appropriately, with the secret word being the provide word in the argument, among other things.

public String createDisguisedWord(String word)Precondition: none.Postcondition: Returned a string of the same length as the argument, but with all the alpha characters replaced by ?.

public void playGame()Precondition: The word has not already been guessed.Postcondition: Letters were obtained one at a time until the secret word was guessed. The number of guesses and incorrect guesses where displayed.

Details:

If you implement all of the functionality specified above, you are entitled to 45 out of 50 points. To get the other 5 points (10%!), giving you 50/50, you need to implement the Web service portion of the program. The requirement is that you must use a randomly generated word from a dictionary Web service and use it as the word to guess. Namely, you are to provide this additional method:

public void initialize()Precondition: none.Postcondition: All of the attributes were initialized appropriately, with the secret word being generated randomly from a dictionary Web service, among other things.

To randomly generate a word from a collection, see below. (Coming soon …)

WSDL: http://services.aonaware.com/DictService/DictService.asmx?WSDL

Page 3: Reminder: - Illinois State University …  · Web viewAll programming assignments in this course are individual assignments. ... makeGuess(c) guesses that character c is in the word.

A class with the main method to test your Hangman class is provided in TestHangman.java.

Starting from this program onward, you are to provide an UML class diagram to depict the details of the class definition.

Submission Requirements: Create a computer-generated class diagram for the program. Zip just your class diagram and java files into a single file named prog3.zip. Submit

prog3.zip to your lecture section (1 or 4), Project 3 using web submit. Turn in the class diagram and a printout of your source code (.java files) in a folder with

your name printed clearly on the front top right corner. 

Sample Interactions:

Let’s play a round of hangman.

The disguised word is <?????????>Guess a letter: eGuesses made 1 with 0 wrong

The disguised word is <??????e??>Guess a letter: aGuesses made 2 with 0 wrong

The disguised word is <?a????e??>Guess a letter: hGuesses made 3 with 0 wrong

The disguised word is <ha????e??>Guess a letter: gGuesses made 4 with 1 wrong

The disguised word is <ha????e??>Guess a letter: pGuesses made 5 with 1 wrong

The disguised word is <happ??e??>Guess a letter: yGuesses made 6 with 2 wrong

The disguised word is <happ??e??>Guess a letter: iGuesses made 7 with 2 wrong

The disguised word is <happi?e??>Guess a letter: nGuesses made 8 with 2 wrong

The disguised word is <happine??>Guess a letter: sGuesses made 9 with 2 wrongCongratulations, you found the secret word: happiness