This tutorial covers two applications of the state pattern as preparation for the Hangman project.
Create a directory for this lab, and copy the files
~comp212/public_html/01-spring/labs/04/*.java
.
These are the Java stub code for the design of a "smart word" given by the
following UML diagram.
In the above diagram, AWord
is an abstract class
to represent the input word in the Hangman game.
An AWord
can be empty or non-empty:
AWord
can be hidden or visible:
String
representation is
an underscore ("_").
String
representation is the
that of the character itself.
See the provided AWord.java for its definition.
The characters in a concrete non-empty AWord
are "smart" and know how to compare themselves with other characters.
They are implemented using the state pattern.
See the provided WordChar.java for its definition.
Hidden
class.
Visible
class.
WordChar
and its derived classes.
EmptyWord
class.
NonEmptyWord
class.
AWord
and its derived classes.
Your labbies will give you guidance, but will not help you write the code. These exercises constitute a non-trivial part of the current Hangman project.