Date: Mon, 18 Mar 2024 22:28:10 -0500 (CDT) Message-ID: <1618696263.1651.1710818890878@wiki-n2.rice.edu> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_1650_711127516.1710818890876" ------=_Part_1650_711127516.1710818890876 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Due Wednesday, 13 April 2010 at 11:00 A.M.
This assignment has a long description but the coding involved is straig= htforward. Most of the code for the full application has been written as su= pport code by the course staff. In our solution, the remaining code that yo= u must write (excluding test code) consists of approximately 250 lines (inc= luding comments and whitespace lines).
Rice student J. H. Acker has decided to drop out of school and become a = high-tech billionaire by marketing a virtual reality game based on Acker's = own personal hygiene. The game is called SimLaundry 2010, and it models the= laundry habits of a typical college student. In this assignment, you will = help Acker create this game, in return for a cut of the profits and a good = Comp 211 grade.
We will assume there are only three types of clothing: shirts, pants, an= d socks. (We will all enjoy this assignment a lot more if we don't have to = think about Acker's underwear.) Acker neatly stacks clean shirts, pants, an= d socks in separate piles on a shelf in his closet.
When changing clothing, Acker throws dirty clothing onto a pile in the c= orner of the closet, then selects the top clean item of a particular type f= rom 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 recen= tly worn article of that type from dirty laundry pile, smells it, and alway= s decides it can be worn again after all. (Acker never has to go naked, bec= ause there is at least one item of the desired type in the laundry, namely = the one Acker just removed.)
When doing laundry, Acker removes fifteen (Studen=
tEnvironment.MAX_LOAD
) or fewer, if the pile isn't that large, items=
from the top of the dirty clothes pile. In the simulation, a load of cloth=
es is laundered and dried instantaneously and placed on a table for clean c=
lothes reserved for Acker in the laundry room. Acker changes clothes so inf=
requently that the washing and drying time is negligible, so our simulation=
is a good approximation. The garments in each load of clean clothes are pi=
led in exactly the same order they appeared in the dirty pile. Acker fills =
the washer and dryer so full that the clothing doesn't get jumbled up.
Eventually Acker retrieves the oldest clean laundry load, folds it, and = places it on the closet shelf. In the process, he reverses the order of the= clothing within the load; whatever was on the bottom of the pile on the la= undry table is now on top of the appropriate pile (shirts, pants, or socks)= of clean clothes on the shelf. Hence, if a blue shirt was on top of a whit= e one in the dirty clothes pile and they are washed in the same load, then = the white shirt will be on top of the blue one on the closet shelf.
Acker periodically receives gifts of clothing from relatives, which are = placed on top of the appropriate pile on the closet shelf. He never buys any clothes.
Acker never discards clothing, no matter how threadbare, but does, on ra= re occasions, lose some. While Acker does not lose clothes being worn,= but they can be lost from anywhere else, including the closet shelf, the d= irty laundry pile, and the laundry room.
For the purposes of this assignment, a pair of socks is an indivisible a= rticle of clothing; we make the unrealistic assumptions that single socks a= re never lost and that Acker does not wear mismatched socks. Also, you need= n't be any more concerned than Acker is about separating white and dark lau= ndry or other such niceties.
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. This file will unzip into a self-contained file tree with =
root directory HW10
. This directory contains the following:
hw10.drjava
-- the DrJava project file for this assignment=
. Everything should already be set properly in it. =
Just start DrJava and go to the Project/Open...
menu item to o=
pen it.src
folder - the root of the source tree.  =
; The packages are edu.rice.comp211.laundry.XXX
, so the actual=
Java files are quite a ways down. This is the "Project Root" o=
f the DrJava project.classes
folder- the root of the compiled code tree. &=
nbsp; This is this is the "Build Directory" of the DrJava project.data
folder -- Test files ("xxxIn.txt
) and ex=
pected output files (xxxOut.txt
) that you can use to test your=
work. This is the "Working Directory" of the DrJava project.=
li>
doc
folder -- The Javadocs for the project. Op=
en the index.html
file in your browser to see the JavadocsAfter unzipping the laundry.zip
file, you can open the DrJa=
va laundry project by starting DrJava, setting the Language Level to
Full Java
, pulling down the
menu and selecting the <=
strong>Open
command. In the file chooser t=
hat pops up, select the project profile file laundry.drjava
em=
bedded 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 t=
he Save
command in the Project
menu. You can also=
save individual files within the project using the Save
butto=
n on command file or the File
menu.
Your assignment is to fill =
in the stubbed out members of the DoCommandVisitor
&nbs=
p; 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 ma=
y choose to define some new classes to support your DoCommandVisitor<=
/code> class implementation. The
Student
class which repeatedl=
y invokes DoCommandVisitor
models the laundry habits of Acker.=
In our test simulations, we will typically only create a single instance o=
f Student
representing Acker, but your code should support mul=
tiple students (e.g., Acker and his brothers) at a time. Since these studen=
ts 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 Mode The supplied DrJava project is set up to run the GUI version of the simu=
lation. Thus, clicking on the The GUI version also allows you to run individual commands. Select=
the " The " Text Mode You may find it easier to run the simulation as a textual input applicat=
ion. Simply right-click the {edu.rice.comp211.laundry.Main.java=
}} file and select " In the text mode, you simply type in each command, such as " Note: Complete testing of your Test each case by creating a test cases that call each case=
explicitly with known host and See sample laundry test class The Use the test files in the Initially, the provided framework should compile but Important Note: When the simulation beg=
ins, Acker is wearing white pants, white socks, and a white shirt. The clos=
et shelf, dirty laundry pile, and laundry facilities are all initially empt=
y. Assume that the supplied test f=
iles are NOT exhaustive!! You are responsible for the complete =
testing of your code! 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 Your solution will be graded using the textual interface. Graphical inte=
rfaces are notoriously difficult to test and all of the graphical interface=
code is part of our support code anyway. Your correctness and testing scor=
es (which each count 25% of your grade) will be based on how well your impl=
ementation of each command complies with the given specifications and on ho=
w well you demonstrate this compliance with test cases. You can test your D=
oCommandVisitor using the same approach given in our 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 shoul=
d do very well on this aspect of the assignment. The remaining 15% of your =
grade is based on your documentation, particularly your This assignment will require that you write code that is a mixture =
of delegation model programming, where one delegates from one object t=
o another to achieve the desired processing, and imperative programming whe=
re a defined control flow is set up, such as with The best approach is to default to a delegation mode, looking to create =
your processing algorithms as a delegation chain from one object to th=
e next. However, you will discover that the nature of cer=
tain objects, the Remember the mantra of delegation model programming: If your p=
rocess depends on the =
type of an object, then delegate to that object. =
Visitors are expressly designed for exactly this sort of type-dependent de=
legation model processing. Use imperative programming sparingly -- only if and when you absolu=
tely need it! You are not at all required to do this, but as a benchmark, it shou=
ld be noted that the staff solution implements each case of Your program executes a loop that repeatedly reads input from an input "=
process" that returns In addition to performing the specified command, your program should out=
put a brief description of for each command that it performs in the exa=
ct format described below. In the following list of commands, the =
output line specifies what your program should print. For this assignment, you should be concerned about relevant asymptotic e=
fficiency. Choose the simplest representation that yields good performance =
on inputs of plausible size. Changing an article of clothing should take constant time (i.e.=
, no searching should be done) provided there's an appropriate garment on t=
he shelf. If the shelf contains no clothing of that type, then in the commo=
n case we expect to find one of those near the bottom of the pile, no matte=
r how big the pile is: make that case fast. Infrequent operations need not =
be particularly fast, because they have little impact on the running time o=
f the entire system. (Suppose one operation accounts for 5% of the running =
time, and we can make it run 10 times as fast. How does that compare to mak=
ing an operation that accounts for 25% of the running time twice as fast?)<=
/p>
With Acker initially wearing white shirt, socks, and pants, given the in=
put: your program should produce: The sample input and output files You are responsible for testing your own program. The program starts execution using the special method Since your class containing in the DrJava Interactions Pane to run the program on input from file String
return=
value of the cases of the DoCommandVisitor=
is the output of processing that
. For example, =
if the expected output of processing a Change
command is "S=
tring
object that you should return from the appropriate case when p=
rocessing that Change
command object, i.e. it accepts your
. Output will be displayed in the DrJava console. =
If you simply hit the DoCommandVisitor
visitor object. <=
/p>
Running the Simulation
Run Project
button i=
n DrJava will run the GUI version of the simulation (edu.rice.comp211=
.laundry.ui.SimLaundry2010Application
), which enables you to load te=
st files and either step through them one command at a time or run all the =
commands automatically. The output will appear in the Interacti=
ons pane.GUI
" mode from the drop list in the lower left corner of=
the window. 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).Threaded
" mode allows you to simulate multiple student=
s sharing laundry piles. Each student runs a difffernt set of command=
s from individually specified input files. There appears t=
o be a latent threading bug that has nothing to do with the student code th=
at can pop up occasionally and crash the simulation. Running mu=
ltiple students is not a requirement here and nothing in the student-writte=
n code would affect this, so don't worry about running in Threaded mode, though it is kind of interesting to watch.
Run File
" or change the the DrJava project=
properties to change the Main Class
to this classand then use=
the Run Project
button. =
receive blue socks
" into the input box that will appear in =
;the Interactions pane. See below for more information on the c=
ommand format. The output will show immediately below in the Interact=
ions pane and new input box will appear.adjectives
MUST be SINGLE words. Testing
DoCommandVisitor=
cases is required.Command
parameters. Then proceed to test the=
visitor as a whole.edu.rice.comp211.laundry.tests.Laund=
ryTest
for examples of how to test an entire command both manually a=
nd by using an input test file and comparison output file.Test Project
button in DrJava runs all of the JUni=
t test files in the project.data
folder as guides for inputs =
and expected outputs. For example, given the text input in samp=
leIn.txt
, your program should generate the text in sampleOut.t=
xt
. testIn.txt
is a fairly exte=
nsive test. You'll probably want to start with something smalle=
r such as sampleIn.txt
or tinyIn.txt
though. LaundryTest=
code> will fail because most of the members in the key class
DoComman=
dVisitor
have been stubbed out.Development Proc=
ess Recommendation
DoCommandVisitor
first =
and then move on to the harder cases. In the opinion of the sta=
ff, the case in order from easiest to hardest are approximately (there=
is definitely room for argument here!)
forOutfit
forReceive
forFold
forLaunder
forLose
forChange
Grading
LaundryTest.java=
class. These tests use the simulate
method in St=
udent
to drive the execution of DoCommandVisitor
. If yo=
u write some utility methods fopr BiLists
you should separatel=
y test these methods. You are NOT responsible for testing any of our suppor=
t code in HW10.zip
including the BiList
class.javadoc
comments for classes and methods.Delegation Model Programming vs. Imperative Programming
if-else
or {=
while}} loop constructs and the objects are processed by following this con=
structed control flow and processing information extracted from the re=
levant 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. BiList
in particular, will force you into an=
imperative mode where you will have to use the BiList
's itera=
tors in conjunction with conditionals and loops. Effecien=
cy concerns (see below) will also play a role in which programming sty=
le you are using at any given moment. DoCommand=
Visitor
as a single return
statement. This =
should tell you something about the power of delegation in this assignment.=
Form of Event Commands
Command
objects. The input process (prov=
ided by our supporting framework) reads a series of event description comma=
nds, one to a line, either from the console or from a file. The input proce=
ss converts a stream of characters to Command
objects which ar=
e passed to your program.
receive=
<adjective> <article>
receive=
d <adjective> <article>
StudentEnvironment
. For ex=
ample,=20
receive=
argyle socks
receive=
d argyle socks
argyle socks
to the top of the socks=
pile on the shelf. lose &l=
t;adjective> <article>
lost &l=
t;adjective> <article>
StudentEnvironment
accordi=
ngly. If Acker is wearing it, the simulation outputs=20
Acker i=
s wearing <adjective> <article>
StudentEnvironment
unchanged. If the ite=
m does not exist, the simulation outputs=20
<adj=
ective> <article> does not exist
StudentEnvironment
(i.e. Acker) unchange=
d. change =
<article>
doffed =
<adjective> <article>, donned <adjective> <article>
If Acker has no clean garment of the specified type, the status string ret=
urned should indicate this. For instance, suppose Acker was asked to change=
his pants when he has no clean pants and is already wearing black-in=
k-grunge pants
:=20
Nothing=
to change into! Doffed black-ink-grunge pants, donned black-ink-grunge pan=
ts
launder
washed =
<adjective> <article>, ..., <adjective> <article>
nothing=
to wash
fold
folded =
<adjective> <article>, ..., <adjective> <article>
nothing=
to fold
folded =
empty load
outfit
wearing=
<adjective> <shirt>, <adjective> pants, <adjective>=
; socks
<=
a href=3D"/confluence/display/cswiki/hw10details_S11">Click here for Supporting Code and Programming Detai=
ls
Efficiency
Example
receive=
blue socks
receive green pants
receive red shirt
change socks
receive yellow shirt
change shirt
outfit
change socks
launder
change pants
fold
change socks
receive=
d blue socks
received green pants
received red shirt
doffed white socks, donned blue socks
received yellow shirt
doffed white shirt, donned yellow shirt
wearing yellow shirt, white pants, blue socks
doffed blue socks, donned white socks
washed blue socks, white shirt
doffed white pants, donned green pants
folded blue socks, white shirt
doffed white socks, donned blue socks
tinyIn.txt
and tiny=
Out.txt
are a good starting point for testing your program but they =
are far from exhaustive.Supplementa=
l Program Running Information
public stati=
c void main(String[] args)
in class Main
. The mai=
n
method interface is the only vehicle for executing Java programs d=
irectly from the command line. (DrJava has a main
method for t=
his reason.)main
is called edu.rice.c=
omp211.laundry.Main
, you can enter the linejava ed=
u.rice.comp211.laundry.Main -t <infile>
Run Project
button, this action is equiv=
alent to entering the line
java ed= u.rice.comp211.laundry.Main
which runs the program with terminal input as the input file. In this ca= se, the program will prompt you for the input of each command in a box with= in the Interactions Pane.
You can also run the program from the command line (a terminal) in the <=
code>laundry directory of the program file tree.
The input line
java ed= u.rice.comp211.laundry.Main -t <infile>
should produce exactly the same results as executing the same line in th=
e DrJava Interactions Pane. You can redirect the output to a the file <outfile>
by typing
java ed= u.rice.comp211.laundry.Main -t <infile> > <outfile>
DrJava does not support output redirection but you can copy the text pri= nted in the console and paste it into a file using your editor of choice.= p>