|
| |||||||||||||||||||||||||||||||||||||||||||
|
|
Start of topic | Skip to actions
Homework 10: SimLaundry 2010Due 1 April 2009 at 11:00 A.M. (Wednesday before class)PrefaceThis assignment has a long description but the coding involved is straightforward. Most of the code for the full application has been written by the course staff. In the solution written by the course staff, the code remaining for you to write consists of approximately 175 lines (including some terse comments and whitespace lines).OverviewRice 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, and 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, and socks in {\em separate} piles on a shelf in his closet. 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.) When doing laundry, Acker removes fifteen (or fewer, if the pile isn't that large) items from the top of the dirty clothes pile. In the simulation, a load of clothes is laundered and dried instanteously and placed on a table for clean clothes reserved for Acker in the laundry room. Acker changes clothes so infrequently that the washing and drying time is negligible, so our simulation is a good approximation. The garments in each load of clean clothes are piled 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 laundry 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 white 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 rare occasions, lose some. Not even Acker loses 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 DoThe course staff is providing a framework for writing this program that includes many classes and interfaces. The framework is available either as a a single file HW10.java (with a skeleton definition for the classStudent) or as an archive (.zip file) laundry.zip of many files, one for each class and interface in HW10.java.
Your job is to fill in the members of the Student class which is provided in skeleton form. In the process you may have to define some new classes to support your Student class implementation. The Student class 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 writing your code is OO style.
The 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 CommandsYour program executes a loop that repeatedly reads input from an input ``process'' that returnsCommand 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.
Supporting Code and Programming DetailsOur supporting framework is provided in two different forms:
public so all of the code can be placed in a single file. We are providing multi-file version of the source so that you can (optionally) gain experience with code bases where every public class resides in a separate file. All subsequent assignment will use the package system where most classes are public and reside in separate files.
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:
!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.
Your
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
The file
The
Each call on
The
Your program must pass a boolean debug= flag to the
When we upload the graphics version of the
EfficiencyFor this assignment, you should be concerned about relevant asymptotic efficiency. 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 the shelf. If the shelf contains no clothing of that type, then in the common case we expect to find one of those near the bottom of the pile, no matter 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 of the entire system. (Suppose one operation accounts for 5% of the runtime, and we can make it run 10 times as fast. How does that compare to making an operation that accounts for 25% of the runtime twice as fast?) ExampleWith Acker initially wearing white shirt, socks, and pants, given the input:receive blue socks receive green pants receive red shirt change socks receive yellow shirt change shirt outfit change socks launder change pants fold change socksyour program should produce: received 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 socksThe sample input and output files tinyin and tinyout
are a good starting point for testing your program but they are far
from exhaustive.
You are responsible for testing your own program. Since your class
containing main is called Student, the terminal command
java Student < infile > outfilewill take input from file infile and direct output to
file outfile. If you omit > outfile, output
will appear in the standard output stream.
You can run the main method from within DrJava by typing
java Student infileDrJava does not recognize command line input or output redirection, so there is no way to redirect output to a file, but it is printed to the console tab. The infile command
argument is supported by the skeleton code we have provided in the Student class.
AddendumThe graphical interface code was written on the assumption that your program resides in a package namedlaundry and that numerous fields of classes in your program are public. It also relies on deprecated library classes and has no supporting test code. It is a major project to rewrite it to work with the current problem specification. The course staff may succeed in getting a version working later in the term, but not before Wednesday. You can ignore all references to "graphics" in the assignment.
Topic Actions: Edit | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r44 < r43 < r42 < r41 < r40 | More topic actions
Webs: Main | TWiki | Africa | CPSX | EmbeddedSystems | Gpce | Houston | International | K12 | MetaOCaml | MulticoreOCR | ProgrammingLanguages | RAP | RIDL | Sandbox | SpeechClub | Teaching | Texbot | WG211 Web Actions: | ||||||||||||||||||||||||||||||||||||||||||
This work is licensed under a Creative Commons Attribution 2.5 License. Please follow our citation guidelines.