...
When changing clothing, Acker throws dirty clothing onto a pile in the
corner of the closet, then selects the top clean item of a particular type
from the closet shelf; the resulting outfits rarely coordinate, but Acker
is no slave to fashion. If there are no clean clothes of a particular
variety, Acker resorts to using dirty laundry and removes the least
recently worn article of that type from dirty laundry pile, smells it, and always decides it can be
worn again after all. (Acker never has to go naked, because there is at
least one item of the desired type in the laundry, namely the one Acker just
removed.)
...
The Student
class includes:
...
the name of the student,
...
the closet shelf with its piles of clean clothes,
...
the dirty laundry pile, and
...
...
<li>
the laundry room with its piles of laundered garmets sitting on tables.
...
and methods to
manipulate those data representations to perform the specified simulation.
Wiki Markup |
---|
When the simulation begins, Acker is |
wearing _white_ pants, _white_ socks, and a |
white
_white{_}shirt. The closet shelf, dirty laundry pile, and laundry facilities are all |
initially empty. Your program should start execution using the special method |
{{public static void main(String\[\] args) |
}} which is the only vehicle for executing Java programs directly on the command line. |
(DrJava has a {{main}} method for this reason.) |
Form of Event Commands
Your program executes a loop that repeatedly reads input from an input ``process'' that returns
Command
objects. The input process (provided by our supporting
framework) reads a series of event
description commands, one to a line, either from the console or from a file. The input process converts
a stream of characters to Command
objects which are passed to your program.
In addition to performing
the specified common, your program should output a brief description of for each command that it performs
in the exact format described below. In the following list
of commands, the output line specifies what your program should print.
HTML |
---|
<ul> |
HTML |
---|
<li> |
receive adjective article
receive adjective article
means means Acker received a gift of the specified article of clothing.
In response, the simulation outputs
...
and adds the argyle socks
to the top of the socks
pile on the shelf.
...
lose adjective article
means Acker misplaced the specified article of clothing.
If the item exists and Acker is not wearing it, the simulation outputs
...
and leaves the StudentEnvironment
unchanged.
HTML |
---|
<li> |
change article
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
outputs
...
describing the article doffed and the article donned.
...
launder
means Acker washed and dried a load of laundry.
If the dirty clothes pile is not empty, the simulation outputs
...
Code Block |
---|
nothing to wash |
HTML |
---|
<li> |
fold
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
outputs
...
Code Block |
---|
folded empty load |
HTML |
---|
<li> |
outfit
asks "what is Acker wearing?" The simulation outputs
Code Block |
---|
wearing <em>adjective</em> shirt, <em>adjective</em> pants, <em>adjective</em> socks |
HTML |
---|
</ul> |
Supporting Code and Programming Details
...
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:
...
...
<ul>
HTML |
---|
<li> |
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
HTML |
---|
<li> |
ReadIteratorI
which includes methods for moving a cursor
through lists implementing the EnumI
interface.
HTML |
---|
</ul> |
The interfaces The interfaces are already defined in the framework provided by the course staff.
...
Your Student
class must implement the StudentEnvironment
interface, which includes
the simulate
method supporting
the laundry simulation. Within
this class you must implement that return values of type
EnumI and ReadIteratorI, the remaining two
interfaces.
The IOProcess
interface that provides your program with a command input stream introduces 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 we will subsequently
provide you with an graphical
IOProcess that animates the state of your implementation before each
command. This IOProcess will expect 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.
...
Your program must pass a boolean debug {{ flag to the =IOProcess}}
it is using ( TerminalIO
for now ). The value of the flag
sould be is true iff the command line argument -d
or -debug
is passed
to main
.
Wiki Markup |
---|
When we upload the graphics version of the {{IOProcess}} , |
your main method in the {{Student}} class should accept a command |
line argument {{\-graphics}} (passed in the {{String\[\] arguments}} array to =main=) |
indicating that the graphics version of |
the {{IOProcess}} should be used instead of the terminal version. |
The default should be the terminal {{IOProcess}} . If you are interested |
in implementation details of these interfaces and classes, please read |
relevant source files. |
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.
...