Assignment 3 (15%): Due Sunday October 30, 2011 at 11:59PM |
This program focuses on coming up with, and implementing, a design that is effective. Although we give you the name and general responsibilities of the classes, we do not provide the methods, specifications, etc. for each class. That is a major part of the assignment, in addition to the implementation, and the design is something you've generally never been assigned to do. Because it should help to talk about the design, the assignment is to be done in pairs, as already assigned. (Except in unusual situations, students in pairs will each receive the same grade.)
Program Description
You will write a set of supporting classes for a restaurant management system. This kind of application would be used by the hosts and servers at a restaurant to manage their set of tables, customers, meal orders, employees, and so on. We provide a text-based interface as the "front end" (which will require some modification on your part).
You will need to download support files into your project to run the UI:
RestaurantTextUI.java
, the
text-based user interface
RestaurantMain.java
, the main
method to run the program
ValidInputReader.java
, a
class with utility methods for reading valid input from the user (used by
text UI)
tables.txt
, input file of
tables at the restaurant
Run RestaurantMain
to launch the program. Input files like
menu.txt
should be placed in your Eclipse project's root folder,
the parent of its src/
or bin/
subdirectories. You
must use svn to manage your project, or else any pair work will be extremely
error-prone.
Classes to Design and Implement
Restaurant
, the overall restaurant and its associated data.
This class manages some core data (tables, waiting list, etc.) and serves
as a bridge of communication between other objects in the system. Do not
place too much functionality into the Restaurant
class—do not make it a "God" class. Party
, a group of customers that can eat at the restaurant.
The restaurant charaterizes parties by a party name and by how many people
are in the party. Party names are unique; no two parties in the restaurant
at the same time can have the same name. If a new party of customers
arrives and asks to be seated, and a table large enough to accommodate them
is available, the party will be seated immediately at the smallest
available table that can accommodate the entire party. If there is a tie in
terms of table seats, the lower numbered table is to chosen. Parties larger
than the largest table are refused service. Parties cannot share
tables.Table
, a table at which parties of customers may sit to eat.
Tables are numbered and each can fit a specified number of customers.
Tables are occupied or not occupied. The number and sizes of tables are
read from an input file; a sample input file is provided. The file's
expected format (see Exceptions section) consists of an initial line
containing the restaurant's name, followed by a second line containing a
list of whitespace-separated integers representing the sizes of the tables
in the restaurant. For example:
Alice's Restaurant 4 4 8 4 2 4 2 6 4 2
Servers
, a manager for servers (waiters) and their
allocation to tables in the restaurant. Initially the restaurant has no
servers, but as servers arrive to work for the evening, the system adds
them. Servers are identified solely by ordinal numbers; the first to arrive
for the evening is 1, the second is 2, and so on. Servers can arrive at any
time, and each newly arriving server is given a number value 1 higher than
the highest-numbered server that has ever checked into the system during
this session. When a newly arriving party is seated at a table, a server is
assigned to them (if one exists) in a round-robin fashion. That is, given
the most recently assigned server, the next assigned server is the one with
the smallest number that is greater than the recently-assigned server. If
no server has been assigned yet, the lowest number server overall is
selected. Each server receives the tip money left by parties at his or her
table. The server is assigned to the party as they are seated; if the party
is put onto the waiting list, a server is not yet assigned to them until
they are seated at a table.Utility
, a place to store shared helper code (optional)There are several functions that must be handled by the system—they can be defined in classes, distributed across classes, etc., as you see fit:
A major part of your grade will come from how effectively you design the contents of each class to solve this problem elegantly.
Text User Interface
The RestaurantTextUI
class performs all user input/output. No
other class should perform I/O to/from the console. (Similarly, this class
should do no core computation or storage that is central to the restaurant
management system.) The text UI given to you is mostly complete, but it is
missing a few "hooks" into your code where we can't know in advance exactly how
you will design your classes. So you must edit the provided mostly-complete
text UI class, looking for places that are unfinished and adding small bits of
code there to attach the text UI properly to your objects and their methods.
These parts of the code have been marked with // TODO
comments to
make them easier to find.
Your classes are to exactly reproduce the format and overall behavior found in our sample inputs and sample outputs. In several places the text UI displays amounts of money.
You will have to run the text UI and test individual inputs on your own to verify that your classes are working correctly. But you will need to create additional tests internally (see below) and additional UI-level tests.
input1.txt
, first input
file (a list of everything that was typed into the
Scanner
)output1.txt
, the output
that resulted when the input in input1.txt
was typedinput2.txt
, second input
file (focusing on waiting list manipulation)output2.txt
, the output
that resulted when the input in input2.txt
was typedIf you want to try to exactly match the provided sample solution, put the
provided Scanner.java
in your
project. This Scanner is a re-implementation of Java's Scanner but with "input
echoing" so you can see the user input even if you redirect I/O to/from a file.
If you use Java's Scanner
and redirect input in from a file, it
won't actually show you what the user typed, so your output looks screwy when
you capture it to a file. But this Scanner
does echo if you tell
it to, fixing this issue. To use this, add this Scanner.java
to
your Eclipse project. Make sure that your RestaurantTextUI
imports
java.util.*;
rather than manually importing
java.util.Scanner
individually; if you do the latter, your code
will use Java's Scanner
and not this one. Then recompile your
project and go to the terminal. To make the input echo, you have to pass a
debug flag to the Java VM named scanner.echo and set it to 1. So you do
something like this:
java -Dscanner.echo=1 RestaurantMain < input1.txt > myoutput1.txt
Then you can compare the outputs more easily with something like:
diff output1.txt myoutput1.txt
Exception Checking and Error Handling
Your classes should forbid invalid parameters. If any method or constructor
is passed a parameter whose value is invalid as per this specification, you
should throw an IllegalArgumentException
. The main client program
should not throw any exceptions to the console. If any errors occur, it is
considered a bug in your code. It is encouraged for you to incorporate
exception throwing into the design of your core classes, but you should make
sure to catch and handle those exceptions. The text UI performs its own
checking for the validity of various user input values, such as making sure
that numbers are non-negative. But this is completely unrelated to your own
tests and exception checks. Remember that valid arguments are preconditions and
could be checked by the client. Your core classes' should not assume that
clients are careful (although the clients won't be malicious)
Development Strategy and Testing
It is hubris to try to write all of these classes at once and then
compile/run the overall program. Therefore it is important to write and test
your code incrementally. Think about which order of implementing classes willl
be most effective for your team. Remember that you can insert a "stub" version
of a particular method or entire class that simply has a pair of empty
{}
braces for the method's body (or simply returns a dummy value
like null
or -1
). This may allow you to test
unfinished classes together. Every class you turn in must have an
associated JUnit test class. The degree of testing should be commensurate
with the complexity of the class and its methods.
Sharing testing code you write for this assignment is both inapproporiate and also largely useless. It's inappropriate because it would reveal details about the implementation and design you have used; it would be largely useless because your design likely has different methods, etc. from the designs others produce. You may, however, share text input files or input/output logs that you have created from your runs of the main text UI, to help show illustrative usage of the client that helps to find flaws and bugs.
Grading
The basic grading structure is: 40% for the overall quality of the design; 30% for the overall quality of the implementation; and 30% for the overall quality of tests.
For the design, it is important to demonstrate (through comments, as well as the design structures themselves) effective use of module specifications, effective use of cohesion, effective reduction of coupling, effective use of subtyping and subclassing, etc. For the implementation, the correctness is the major objective, with style the secondary objective. Correctness includes handling the error conditions as well as the common cases. For the testing, appropriate levels of testing are the key objective.
Style and Design Guidelines
We will cover some basic style and design guidelines in lecture (in addition to the modular design already covered), and you will be responsible for using those guidelines. The design issues such as clear specifications, good cohesion, weak coupling, effective use of subtyping and subclassing, aoviding representation exposure (consider carefully the use of immutability, for example), etc are the most important. Lower-level issues are also important, but cannot overcome a poor design. Some of these issues include (many but not all of which we will have discussed):
modifies
,
effects
, etc.) must be clear and should be done as part of the
design itself, updated as needed during implementation.static
. public
.equals
,
hashCode
, compareTo
, etc. as needed.For reference, our solution contains roughly 210 "substantive lines" (which excludes things like blank lines, comments, and {} brace lines), excluding our Utility.java shared code. But this number is just provided as a sanity check; you do not need to match it or be close to it to get full credit.