...
In the text mode, you simply type in each command, such as "receive blue socks
" into the input box that will appear in the Interactions pane. See below for more information on the command format. The output will show immediately below in the Interactions pane and new input box will appear.
Note: adjectives
MUST be SINGLE words.
Testing
Complete testing of your DoCommandVisitor
cases is required.
...
- The command
means Acker received a gift of the specified article (<adjective> <article>) of clothing. In response, the simulation outputsCode Block receive <adjective> <article>
and updates the state of theCode Block received <adjective> <article>
StudentEnvironment
. For example,
generatesCode Block receive argyle socks
and adds theCode Block received argyle socks
argyle socks
to the top of thesocks
pile on the shelf. - The command
means Acker misplaced the specified article of clothing. If the item exists and Acker is not wearing it, the simulation outputsCode Block lose <adjective> <article>
and updates the state of theCode Block lost <adjective> <article>
StudentEnvironment
accordingly. If Acker is wearing it, the simulation outputs
and leaves theCode Block Acker is wearing <adjective> <article>
StudentEnvironment
unchanged. If the item does not exist, the simulation outputs
and leaves theCode Block <adjective> <article> does not exist
StudentEnvironment
unchanged. - The command
means Acker doffed the specified article of clothing, discarding it in the dirty laundry pile, and donned a replacement article using the protocol described above. In response, the simulation outputsCode Block change <article>
describing the article doffed and the article donned.Code Block doffed <adjective> <article>, donned <adjective> <article>
- The command
means Acker washed and dried a load of laundry. If the dirty clothes pile is not empty, the simulation outputsCode Block {{launder}}
listing the clothes in the order they were removed from the dirty clothes pile. If the dirty clothes pile is empty, the simulation outputsCode Block washed <adjective> <article>, ..., <adjective> <article>
Code Block nothing to wash
- The command
means Acker retrieved a load of laundry, folded it, and put it on the closet shelf. If a load of laundry is available, the simulation outputsCode Block fold
for the oldest unfolded load. List the clothes in the order they are placed on the shelf. Hence the top garment on the shelf should be the last one listed. If no load of laundry has been washed and dried, then the simulation outputsCode Block folded <adjective> <article>, ..., <adjective> <article>
If the oldest load is empty (because all items in it were lost), the simulation outputsCode Block nothing to fold
Code Block folded empty load
- The command
asks "what is Acker wearing?" The simulation outputsCode Block outfit
Code Block wearing <adjective> <shirt>, <adjective> pants, <adjective> socks
Click here for Supporting Code and Programming
...
Details
...
Our supporting framework is provided in the zip file laundry.zip\. The test input in the file sampleIn
(with corresponding output) sampleOut
is far from comprehensive.
All of our supporting code is included in the unzipped project. Each file resides in a package that is identified by a package
statement at the beginning of the file. Most support classes are public
so that they can be accessed anywhere. Classes without a visibility modifier have "default" visibility, which means that they can only be accessed from classes within the same package.
Our supporting framework includes an input processor that reads event commands from the input stream and returns high level data representations for these commands. The input processor can also print debugging output describing the state of your simulation before each command is performed. To communicate with your code, the input processor uses four interfaces:
IOProcess
which describes the visible methods supported by the input processor;
StudentEnvironment
which describes methods for inspecting the state of Acker's environment;
EnumI
which describes methods for inspecting (but not mutating!) lists within Acker's environment; and
ReadIteratorI
which includes methods for moving a cursor through lists implementing the EnumI
interface.
The interfaces are already defined in the framework provided by the course staff.
The input processor class TerminalIO
implements the IOProcess
interface. You are welcome to inspect the code of TerminalIO
but it relies heavily on the Java I/O library, particularly the class StreamTokenizer
. To understand this code, you will need to read Chapter 11 of JLS (or similar reference). The framework also includes implementations of EnumI
and ReadIteratorI
as part of a BiList
(mutable circular doubly linked list) class implementation.
The Student
class implements the StudentEnvironment
interface, which includes the simulate
method supporting the laundry simulation. The simulate method contains a loop that reads commands from its IOProcess
and invokes DoCommandVisitor
on each command. Within the DoCommandVistor
class you must implement methods that process the various possible commands.
The program includes two class definitions defining unions (composites without recursion): Garment
, specifying the representation of garments that appear in the input stream, and Command
, specifying the representation of event description commands. Both classes include the hooks required to support the visitor pattern. The data definition for Garment
is important because the graphical version of the user interface included in the framework animates the state of your implementation before each command. This graphical user interface (GUI) expects the garments that appear as elements in lists (as revealed by the EnumI
and ReadIteratorI
interfaces) to be instances of the Garment
class. Hence, you must use the representation of garments that our class Garment
provides.
The file DoCommandVisitor.java
contains comments describing all of the members that you need to write. This class could have been defined as an inner class of Student
but we made it a top level class to simplify debugging.
The IOProcess
interface includes a method PrintStream open(StudentEnvironmenta, boolean debug)
which initializes an IOProcess
object for a laundry simulation of the specified environment and returns the PrintStream
object to be used for terminal output. (Up to now you have implicitly used the PrintStream
object System.out
.) The PrintStream
method println(String s)
prints the string s
followed by a newline character to the PrintStream
. The boolean debug
argument indicates whether or not debugging output should be produced. The IOProcess
interface also includes a method nextCommand
which reads the next command from the input channel supported by the IOProcess
object.
Each call on nextCommand
returns the next command in the stream provided by the IOProcess
object, until it reaches an end-of-file (<control>-d
from the keyboard). End-of-file is reported as a null reference of type Command
.
The nextCommand
method in TerminalIO
processes character strings consisting of words separated by ``space'' characters such as ' '
and '\n'
. A word
is any sequence of printable characters other than space, '\n'
(newline), and '\r'
. (return). An adjective
must be a single word. An article
must be one the words shirt
, pants
, or socks
. The same adjective, say argyle
may be applied to garments of different types, but there are no duplicate items of clothing.
The program passes a boolean debug flag
to (TerminalIO
). The value of the flag is true iff the command line argument -d
or -debug
is passed to main
.
The Graphical User Interface (GUI)
The initialization of the GUI creates an Acker Student object and associated DoCommandVisitor. Each GUI event triggers the execution of DoCommandVisitor; in some cases, such as reading input from a file, it triggers the execution of DoCommandVisitor on a stream of Commands. In essence, the event-handling loop built-in to the Java Swing framework is used to drive the computation rather than a separate loop in the main thread such as the one in the simulate method in Student.
...
Efficiency
For this assignment, you should be concerned about relevant asymptotic efficiency. Choose the simplest representation that yields good performance on inputs of plausible size.
...