Homework 10: SimLaundry2010SimLaundry 2010
Due Friday Wednesday, 9 13 April 2010 at 11:00 A.M.
Preface
This assignment has a long description but the coding involved is straightforward. Most of the code for the full application has been written as support code by the course staff. In our solution, the remaining code that you must write (excluding test code) consists of approximately 250 lines (including comments and whitespace lines).
...
Acker never discards clothing, no matter how threadbare, but does, on rare occasions, lose some. Not only does Acker lose While Acker does not lose clothes being worn, but they can be lost from anywhere else, including the closet shelf, the dirty laundry pile, and the laundry room.
For the purposes of this assignment, a pair of socks is an indivisible article of clothing; we make the unrealistic assumptions that single socks are never lost and that Acker does not wear mismatched socks. Also, you needn't be any more concerned than Acker is about separating white and dark laundry or other such niceties.
What You Must Do
Download the supplied code here: HW10.zip
The course staff is providing a framework for writing this program that includes many classes and interfaces. The framework is packaged as a zipped DrJava project laundry.zip. This file will unzip into a self-contained file tree with root directory HW10
. This directory contains the following:
...
After unzipping the laundry.zip
file, you can open the DrJava laundry project by starting DrJava, setting the Language Level
to Full Java
, pulling down the Project
menu and selecting the Open
command. In the file chooser that pops up, select the project profile file laundry.drjava
embedded in the file in the unzipped file tree for laundry.zip
. You can save the project state at any point during a DrJava session using the Save
command in the Project
menu. You can also save individual files within the project using the Save
button on command file or the File
menu.
Your assignment is to fill in the stubbed out members of the DoCommandVisitor
(members with degenerate bodies (return "";
). All required areas in the code are clearly marked with comments for the student to complete the code in that area. In the process you may choose to define some new classes to support your DoCommandVisitor
class implementation. The Student
class which repeatedly invokes DoCommandVisitor
models the laundry habits of Acker. In our test simulations, we will typically only create a single instance of Student
representing Acker, but your code should support multiple students (e.g., Acker and his brothers) at a time. Since these students do not interact with each other, supporting this form of multiplicity is a trivial consequence of OO coding style used in the framework.
...
The GUI version also allows you to run individual commands. Select the "GUI
" mode from the drop list in the lower left corner of the window.
Text Mode
You may find it easier to run the simulation as a textual input application. Simply right-click the {edu.rice.comp211.laundry.Main.java}} file and select "Run File
" or change the the DrJava project properties to change the Main Class
to this classand then use the Run Project
button.
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.
Test each case by creating a test cases that call each case explicitly with known host and Command
parameters. Then proceed to test the visitor as a whole.
See sample laundry test class edu.rice.comp211.laundry.tests.LaundryTest
for examples of how to test an entire command both manually and by using an input test file and comparison output file.
The Test Project
button in DrJava runs all of the JUnit test files in the project.
Use the test files in the data} folder as guides for inputs and expected outputs. For example, given the text input in {{sampleIn.txt
, your program should generate the text in sampleOut.txt
. testIn.txt
is a fairly extensive test. You'll probably want to start with something smaller such as sampleIn.txt} or {{tinyIn.txt
though.
Initially, the provided framework should compile but LaundryTest
will fail because most of the members in the key class DoCommandVisitor
have been stubbed out.
Important Note: When the simulation begins, Acker is wearing white pants, white socks, and a white shirt. The closet shelf, dirty laundry pile, and laundry facilities are all initially empty.
Assume that the supplied test files are NOT exhaustive!! You are responsible for the complete testing of your code!
Grading
Your solution will be graded using the textual interface. Graphical interfaces are notoriously difficult to test and all of the graphical interface code is part of our support code anyway. Your correctness and testing scores (which each count 25% of your grade) will be based on how well your implementation of each command complies with the given specifications and on how well you demonstrate this compliance with test cases. You can test your DoCommandVisitor using the same approach given in our LaundryTest.java
class. These tests use the simulate
method in Student
to drive the execution of DoCommandVisitor
. If you write some utility methods fopr BiLists
you should separately test these methods. You are NOT responsible for testing any of our support code in HW10.zip
including the BiList
class.
A major portion of your grade (35%) will be based on your program style. If you write your code in the OO style practiced in this course, you should do very well on this aspect of the assignment. The remaining 15% of your grade is based on your documentation, particularly your javadoc
comments for classes and methods.
The Student
class includes:
...
The GUI will then allow you to create and run one command at a time. This is useful for testing a single command, but may be more tedious than running in text mode (see below).
The "Threaded
" mode allows you to simulate multiple students sharing laundry piles. Each student runs a difffernt set of commands from individually specified input files. There appears to be a latent threading bug that has nothing to do with the student code that can pop up occasionally and crash the simulation. Running multiple students is not a requirement here and nothing in the student-written code would affect this, so don't worry about running in Threaded
mode, though it is kind of interesting to watch.
Text Mode
You may find it easier to run the simulation as a textual input application. Simply right-click the {edu.rice.comp211.laundry.Main.java}} file and select "Run File
" or change the the DrJava project properties to change the Main Class
to this classand then use the Run Project
button.
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.
Test each case by creating a test cases that call each case explicitly with known host and Command
parameters. Then proceed to test the visitor as a whole.
See sample laundry test class edu.rice.comp211.laundry.tests.LaundryTest
for examples of how to test an entire command both manually and by using an input test file and comparison output file.
The Test Project
button in DrJava runs all of the JUnit test files in the project.
Use the test files in the data
folder as guides for inputs and expected outputs. For example, given the text input in sampleIn.txt
, your program should generate the text in sampleOut.txt
. testIn.txt
is a fairly extensive test. You'll probably want to start with something smaller such as sampleIn.txt
or tinyIn.txt
though.
Initially, the provided framework should compile but LaundryTest
will fail because most of the members in the key class DoCommandVisitor
have been stubbed out.
Important Note: When the simulation begins, Acker is wearing white pants, white socks, and a white shirt. The closet shelf, dirty laundry pile, and laundry facilities are all initially empty.
Assume that the supplied test files are NOT exhaustive!! You are responsible for the complete testing of your code!
Development Process Recommendation
It is highly recommended that you take a step-by-step, highly structured approach to this assignment. Take SMALL steps, testing thoroughly before moving to the next step.
Write and test the easiest cases of DoCommandVisitor
first and then move on to the harder cases. In the opinion of the staff, the case in order from easiest to hardest are approximately (there is definitely room for argument here!)
forOutfit
forReceive
forFold
forLaunder
forLose
forChange
Grading
Your solution will be graded using the textual interface. Graphical interfaces are notoriously difficult to test and all of the graphical interface code is part of our support code anyway. Your correctness and testing scores (which each count 25% of your grade) will be based on how well your implementation of each command complies with the given specifications and on how well you demonstrate this compliance with test cases. You can test your DoCommandVisitor using the same approach given in our LaundryTest.java
class. These tests use the simulate
method in Student
to drive the execution of DoCommandVisitor
. If you write some utility methods fopr BiLists
you should separately test these methods. You are NOT responsible for testing any of our support code in HW10.zip
including the BiList
class.
A major portion of your grade (35%) will be based on your program style. If you write your code in the OO style practiced in this course, you should do very well on this aspect of the assignment. The remaining 15% of your grade is based on your documentation, particularly your javadoc
comments for classes and methods.
Delegation Model Programming vs. Imperative Programming
This assignment will require that you write code that is a mixture of delegation model programming, where one delegates from one object to another to achieve the desired processing, and imperative programming where a defined control flow is set up, such as with if-else
or {while}} loop constructs and the objects are processed by following this constructed control flow and processing information extracted from the relevant objects. This mixture is how you can expect a real world program to be constructed -- the world isn't so clean that only one paradigm can totally rule in any situation.
The best approach is to default to a delegation mode, looking to create your processing algorithms as a delegation chain from one object to the next. However, you will discover that the nature of certain objects, the BiList
in particular, will force you into an imperative mode where you will have to use the BiList
's iterators in conjunction with conditionals and loops. Effeciency concerns (see below) will also play a role in which programming style you are using at any given moment.
Remember the mantra of delegation model programming: If your process depends on the type of an object, then delegate to that object. Visitors are expressly designed for exactly this sort of type-dependent delegation model processing.
Use imperative programming sparingly -- only if and when you absolutely need it!
You are not at all required to do this, but as a benchmark, it should be noted that the staff solution implements each case of DoCommandVisitor
as a single return
statement. This should tell you something about the power of delegation in this assignment.
...
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.
...
- 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
(i.e. Acker) 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>
means Acker describing the article doffed and 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 changedoffed <adjective> <article>, donned <adjective> <article>
describing the article doffed and the article donned.Code Block doffed <adjective> <article>, donned <adjective> <article>
article donned.
If Acker has no clean garment of the specified type, the status string returned should indicate this. For instance, suppose Acker was asked to change his pants when he has no clean pants and is already wearingblack-ink-grunge pants
:Code Block Nothing to change into! Doffed black-ink-grunge pants, donned black-ink-grunge pants
- 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
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.
...
You are responsible for testing your own program.
Supplemental Program Running Information
...
Supplemental Program Running Information
The program starts execution using the special method {{public
static
void
main(String
\[
\]
args)
}} in class {{Main
}}. The {{main
}} method interface is the only vehicle for executing Java programs directly from the command line. (DrJava has a {{main
}} method for this reason.)
Since your class containing main
is called edu.rice.comp211.laundry.Main
, you can enter the line
...