Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The programming language used is Java (Eclipse) Introduction Implement a small s

ID: 3631092 • Letter: T

Question

The programming language used is Java (Eclipse)

Introduction

Implement a small system that involves several interacting classes. The end result is a simple game called “hangman” that is likely to be familiar from grade school. A secret word is displayed as a sequence of blank spaces or dashes, for example, the secret word “avocado” would start out being displayed like this:
-------

The player tries to guess the letters. If a letter is guessed correctly, say “o”, it is written in the
corresponding spaces.
--o---o
The goal is to guess all the letters in the word before running out of guesses. Traditionally, each
time a wrong guess is made, another body part is drawn on a stick figure (head, arm, etc.) When
the stick figure is complete, the player loses.

Overview
The parts of the system that you are to implement are the following:
1. The class HiddenWord represents a word that has two forms: the actual secret word, and
also a string that is the “displayed” form of the word (e.g. --o---o).

2. The class HangmanGame is responsible for keeping track of the letters guessed, the number
of wrong guesses, and whether the game is won or lost. Part of the state of a HangmanGame object is a HiddenWord.

3. The class WordGenerator is responsible for choosing a random word from a text file.

Note that none of the classes above should read input or print output. All input or output is done
through a user interface. Two user interfaces are provided for you in the sample code:

TextUIMain is a very short main class that runs a text-based user interface. You should read
this code because it will give you a good idea how the other classes are supposed to work and
will give you an easy way to try them out. Basically the UI is constructed with a given
WordGenerator, and it constructs HangmanGame instances as needed when the user wants to
play a round of the game. (Note that the UI does not ever refer directly to a HiddenWord
object.)

UIMain is a main class that starts up an instance of HangmanUI, a graphical interface for the
game. This does roughly the same thing as the text UI but is more fun and provides a nice
way to see how all the pieces come together to make a complete application. It is not
necessary for you to read and understand the HangmanUI code (though you might find it
interesting).

You should not modify any of the user interface code, other than to possibly change the name of
the file to be read. The UI code may be downloaded from
http://www.cs.iastate.edu/~cs227/assignments/assignment2/hw2_ui_code.zip

Note: the UI code won’t compile until you create the three required classes!
Detailed specifications

See the javadoc online at http://www.cs.iastate.edu/~cs227/assignments/assignment2/doc/

Notes

1. None of the classes that you implement should directly read input or print output. All input
and output is performed by the user interface classes.

2. HangmanGame should use a HiddenWord object appropriately to store the secret word.
Methods of HangmanGame such as getDisplay() and getSecret() should call the appropriate
methods of HiddenWord to obtain the required information. The functionality of HiddenWord
should not be duplicated within HangmanGame.

3. HangmanGame must define this constant:
public static final int DEFAULT_MAX_WRONG_GUESSES = 7;

4. HiddenWord objects should not refer to any instance of HangmanGame. You should be able to
test them independently. For example, you should be able to run code like this:
HiddenWord hw = new HiddenWord("avocado");
System.out.println("Expected '-------': " + hw.getDisplayedWord());
System.out.println("Expected 7: " + hw.countRemaining());
System.out.println("Expected true: " + hw.containsLetter('o'));
System.out.println("Expected '-------': " + hw.getDisplayedWord());
hw.update('o');
System.out.println("Expected '--o----o': " + hw.getDisplayedWord());
System.out.println("Expected 5: " + hw.countRemaining());

5. HiddenWord should store and display the word using lower-case, regardless of how it was
given in the constructor. (The user interfaces always use lower-case letters.)

6. The input file for WordGenerator should contain words separated by whitespace (spaces, tabs,
or newlines). Words themselves should not contain whitespace or punctuation. You can create
your own word files to try out your code, and you are welcome to share them on Blackboard. (It
is common for a word file to have a “theme”, e.g., a fruits and vegetables, kitchen utensils, sea
animals, automobile parts, etc.)

7. WordGenerator should create a single instance of Random upon construction and use that
instance for all word selections.

8. Using Random, it is possible for your WordGenerator to select the same word twice in a row,
or twice during execution of the program. You don’t have to prevent this from happening.
Optionally you could add a check within WordGenerator to avoid selecting the same word
twice, provided you still do the selections randomly.

Ideas for getting started
1. Create the package and the three required classes. Write dummy methods for the
required public methods and constructors. Document each method (you are free to copy
from the provided javadoc).
2. Then you can download the sample code and everything should compile. It will fail if
you try to run it, however.
3. You can work independently on HiddenWord. Refer to the example test code shown in
the notes above. Write some more test cases.
4. HangmanGame depends on having a HiddenWord instance, but if you have a skeleton for
HiddenWord, you can work independently on HangmanGame. Keeping track of the
number of wrong guesses and the guessed letters, for example, should work correctly
even if your HiddenWord isn’t correct yet. Write a unit test.
5. You can work independently on WordGenerator. Be sure you have done lab 7. You’ll
need to read the file twice, once to count the words and once to choose a random one.
6. If you have the other two classes working, it is also possible to try out the UI using a
dummy version of WordGenerator, e.g., in which the getWord method just returns the
word “avocado” or something.

What to turn in
Turn in a zip file containing the six .java files comprising the project, in the correct directory
structure:
w2HangmanGame.java
w2HangmanUI.java
w2HiddenWord.java
w2TextUIMain.java
w2UIMain.java
w2WordGenerator.java

Explanation / Answer

Ok if you want the answer rate my as lifesaver first. Im tired of spending 20 minutes doing a solution and then the person just takes the answer and doesnt rate my answer. PM me for the answer once you have rated it.