CSE 373 Spring 2005
Homework #4
Investor's Helper
April 26, 2005
Starter files (now includes stockportfolio/CommandReader.class)
Javadoc including CommandReader class
Due:
electronically Thursday,
May 5, 8:00 pm; paperwork at beginning of
class the next day. Note: for this and all homework where there
are parters, only one person should do the electronic turn-in
(specifying both parties names), and only one copy of any paperwork
should turned in (with both parties names on all parts), unless
otherwise instructed.
Note: the material below in red was added to the finalized version
4/28/2005.
Objectives
- Use data structures such as queues, lists, maps, etc. where appropriate for problem-solving
- Implement a queue-like structure
- Implement classes so
instances of them can be stored properly in Collections
- Leverage knowledge of string processing.
- Experience work with a partner
Description
The problem to be solved is based upon one in the
G&T textbook: P.4-10, page 198. Start by reading it if you haven't
already.
For this homework, there are some differences from the problem as
stated there, and also some specific implementation requirements.
It is likely that this problem will be expanded upon in a future
homework.
The overall application is conceived as managing a stock portfolio,
which is a collection of stocks that have been bought over time.
The portfolio is modified by executing buy and sell transactions. The
capital gain is computed for each sell transaction.
Problem additions and changes:
- Allow for different stocks to be bought and sold. Stocks
are referred to by a string (such as "Ford Motor", "Adobe", "car toys",
"JVC", etc. Normalize all such stock names to be trimmed of
spaces (on both sides) and case-converted so that only the first letter
of the full name is capitalized (e.g. "Ford motor", "Adobe", "Car
toys", "Jvc").
- Keep track of how many of each stock is owned at any given time.
- You need to detect illegal transactions, in particular, attempting to sell
more stock than is owned. One special case of this is attempting to
sell stock for which no shares are owned. Other illegal cases include
attempting to sell a non-positive amount of a stock, or attempting to sell
for a non-positive price per share. Unless otherwise noted in the
starter code, illegal situations like this are signaled by throwing an
IllegalArgumentException with an appropriate String argument describing the
error. Printing a message on the console is optional. You should
not bring up a dialog box or otherwise block the program.
- The input format shown in the book is not needed.
The classes you write need not read any input files. Instead, you
will write separate test classes that will supply data via
parameters. (At some point we may give you classes with an interface facilitate
testing, possibly reading from a file. You should not depend upon
these for your test classes or for your testing in general).
Implementation requirements
- You should implement a class ObjectDQueue which implements IDQueue.
This is very similar to an ordinary queue of Objects.
- You should implement a class StockQueue which extends ObjectDQueue.
This is very similar to an ordinary d-queue of Objects, but tracks the total
number of stock shares owned.
- You should implement a class Portfolio which implements
IPortfolio. This is the principal top-level class of the
application. A Portfolio keeps track of the stocks that are owned.
Internally to the Portfolio you should use StockQueue objects, possibly
within other data structures that you deem appropriate.
- You
should complete the implementation of StockBlock, by providing a
comparetTo method. This, along with a proper equals method, is
necessary for objects which will be stored in Java Collections.
- Write JUnit test classes for ObjectDQueue, StockQueue and Portfolio.
These should work with anyone's implementation of the classes, not just
your own. (For your own testing, it is also recommended that you
implement a test class for other classes that you
write, but this is not a grading point).
- Just as before (and always): You must use the
exact names for classes and methods as specified here and in any starter code
(etc. etc.).
Getting Started:
- Pick a partner! Exchange contact information and get
acquainted. It might help to discuss general expectations of who
will do what (in terms of classes to be written, tests to be written
and run, paperwork to prepare, etc.). Also figure out where the
"official" versions of the code will reside, how you will exchange
files, what tools will be used, etc. [Note: partners will be switched at least
once before the end of the quarter.]
- Make sure you understand the basic capital gains
calculation. If you know something about taxes, you may realize
that the calculation has been simplified in at least from the authentic
one. For now, follow the rules as outlined in the textbook (even
if you know better!).
- Decide on your basic approach to implementing a queue. Design the
data structures to be used in Portfolio. This can be done without
actually coding anything!
- Set up a project and make sure you have JUnit available, that
asserts are enabled both for compiling and running, etc. Copy the starter code into proper packages and make sure everything compiles
(without having to monkey with package statements, etc.). Skeletons
are provided for all the class mentioned above, and there are also a
number of complete interfaces and helper classes. A couple of the
starter classes won't compile until you have done some work on them,
however -- ObjectDQueue and Portfolio.
- Go
through the starter code carefully to see what is there and where you
need to make changes. As you do this, you might make notes which
will help with what is due on Monday.
Turn in:
On Friday, April 29 in class (no electronic turn-in is
involved): a sheet contain the names of the partners and a Team Moniker
(nickname by which this team is known). If for some highly unusual reason
you are working alone, you must still turn in a sheet of paper stating this
fact, and the reason.
On Monday, May 2, in class (no electronic turn-in is involved): A list
(or better yet, a diagram), of all the classes you expect to implement or
modify, showing
the relationships between them, and their relationship to the starter
classes/interfaces. There is no special format for this list/diagram,
except that it should be easy to read and understand. It may be
freehand. If you are familiar with UML, you may use that format (leave out
most of the UML detail except class/interface names and relationships).
For each class you expect to implement, indicate its implementation status as of
that moment:
- completed and tested
- substantially completed
- created but not complete
- not yet created
The electronic turn in is as mentioned previously, Thursday, May 5.
Please zip up all your source files
and turn in one .zip file. Click
Here to Turn-in
Recommendation: turn in early and often!
On paper in class the next day: a printed copy of the "receipt" from your turn-in. Plus: a short report
which
- has an updated (final) version of the class diagram/list you turned in
earlier in the week
- describes whether what you turned in meets the requirements
- describes briefly the data structures you used, other than than StockQueue
- describes the efficiency of the capital gain calculation algorithm, given
your data structures and the way that you implemented the StockQueue.
- mention any difficulties or special circumstances
- describes in general terms how the work was divided or shared between the partners
Grading
Most of the grading points will come from
- Implementation of the queue classes
- Design of appropriate (includes efficient!) data structures within the Portfolio class
- Correctness of the methods (including the capital gains calculation)
- Correctness, thoroughness, and independence of the test classes
(independence means that your classes would be useful tests for other
people's implementations of the project).
- Following instructions and specifications
- Programming practice (style, comments, etc.). See link on the 373
home page to the Sun Coding Conventions.
- The report
Good luck and have fun!
Notes
If you have questions along the way, either about the assignment or how
to do things, feel free to discuss it on the Message Board (when it is
operational!). Just
don't give away code, or any crucial aspects of the solution. It is
perfectly OK to share insights about using the Java libraries.
Where applicable, write your code to be reusable and modifiable.
In a later homework, you might in fact have an opportunity to reuse or
modify code from this one...