CMSC 341 Spring
2008
Project 1
Assigned
|
Wednesday, Jan
30, 2008
|
Due
|
11:59pm, Friday Feb 15, 2008
|
Updates
|
Feb 6
|
Update and Clarification (Feb 6,
2008)
- For a stock you already own,
its purchase share price can only be changed by buying additional shares
of that stock, not by selling some shares of that stock. A sentence in
Note 4 to the contrary has been deleted (highlighted and strikethrough).
- As stated in Note 6, latest
share price can only be updated by the command SHAREPRICE, not by BUY or
SELL, although it is initialized to the purchase price when you buy that
stock the first time.
Objectives
- To exercise and refresh your
java programming
- To start work with LIST, one
of the simplest but also the widely used data structures, and
- To warm up you for more
complex data structures and more elaborated project assignments later in
this course.
Description
In this project you will implement a simple portfolio for a hypothetical
investor in US
stock market. The investor has a cash
account she can use to buy stocks, and the money she receives from selling
stocks will all go to this account. She also makes cash deposits to and cash
withdrawals from this account from time to time.
The portfolio keeps all the stocks the investor
currently owns. The following information is stored for each stock
- ticker (the symbol of the stock as its
unique ID in the stock market)
- number
of shares currently owned
- purchase
share price
- latest
share price
- gain (percent of change in share price)
Here is an example entry in the portfolio: F 120 6.3525 6.29 -0.9838 (120 share of Ford Motor Company with
purchase share price of 6.3525, latest price of 6.29, and gain of -0.9838%).
The following commands specify
the operations/actions the investor can take in our hypothetical investment
world.
- CASHIN
<amount> -- deposits the given amount of cash to the cash account
and prints the new cash balance
- CASHINOUT
<amount> -- withdraws the given amount of cash from the cash account
and prints the new cash balance
- CASHBALANCE<>
-- prints the current cash balance
- BUY <ticker>
<number of shares> <share-price> -- buys the given number
of shares of the given stock at the given share price.
- SELL<ticker>
<number of shares><share-price> -- sells the given number of
shares of the stock at the given price.
- SHAREPRICE<ticker><
share-price> -- inputs the current price of that stock
- QUERY<ticker>
-- prints out all relevant information of the stock
- COUNTPORTFOLIO
<> -- prints total number of stocks in the portfolio
- PRINTPORTFOLIO<>
-- prints all stocks in the portfolio and their relevant information in descending order of their percent
change in share price.
Note:
- Numbers
of shares one can buy/sell are integers (int),
the tickers are strings, and all other parameters for these commands are
real (float).
- The
cash account should be initialized to zero
- The
gain is calculated as (latest share price – purchase share
prince)/purchase share price.
- Since
the investor can buy and cumulate the same stock at different time with
different share prices, the “purchase share price” and
“percent of change in share price” need to be recalculated
whenever the number of shares of a stock is increased with a new purchase.
These two values
will also be affected when some shares are sold. (You need to
figure out the formulas for the purchase share price, which is actually
the averaged over all the shares currently in the portfolio).
- When
the number of shares of one stock becomes 0 (zero) after one “sell”
transaction, its entry shall be removed from the portfolio.
- The
latest share price is initialized to the purchase price when the stock is
first purchased, it can only be updated by the command SHAREPRICE
thereafter.
- You are free to create java
classes and methods necessary for this project either from scratch or
reuse some from, say Java Collection classes. Use can use a README file justify your choice.
- Be sure to handle exceptions
(e.g., purchase without sufficient fund, try to sell what you don’t
have, withdraw more cash than the current balance, etc.) and print out
proper message.
- You
can submit the output of your own test command file in a text file named p1-output.txt. Be sure that this
file is in plain text format.
Command Line and Command File
Project 1 will be invoked with a command line that consists
of one argument: the name of a file that contains a list of operations
that must be performed on the inventory in that order. An example command line
looks like
Proj1
/afs/umbc.edu/users/y/p/ypeng/pub/cs341s08/test/Proj1/test1
All the commands in a command
file shall be executed in the given sequence. You should echo each command
before it is executed.
Here is an example of the
command file:
PRINTPORTFOLIO
CASHIN 100000
BUY MSFT 20 32.24
BUY BAC 100 42.22
QUERY F
BUY MSFT 10 31.15
QUERY MSFT
SHAREPRICE BAC 43.35
SELL BAC 20 43.35
CASHBALANCE
BUY INTC 20 12.75
COUNTPORTFOLIO
PRINTPORTFOLIO
Project Notes and requirements
- However, you must use
generics for the LIST class you created for holding the portfolio. And
obviously you need to create a class for stocks.
- You are free to create these
and other java classes and methods necessary for this project either from
scratch or reuse some from, say Java Collection classes. You can use a README file to justify your
choice.
- You can assume that the
command file is well-formed as described early,
your program does not need to check the syntactical correctness of the
commands in the file.
- Good documentation is
required, and the comments must be in Javadoc
form.
- Be sure to handle exceptions
(e.g., purchase without sufficient fund, try to sell what you don’t
have, withdraw more cash than the current balance, etc.) and print out
proper messages for exceptions.
Files to Be Submitted
Submit the following files:
- *.java (including
Proj1.java),
- README
Submit the files using the procedure below.
Submission Tools
There are a number of tools available to you to check on your submittal. It is
your responsibility to ensure that the submittal is correct and will result in
a successful compilation of your project. Do not wait till the last minute to
submit your files. Give yourself enough time to check that your submittal is
correct.
If you don't submit a project correctly, you will not get credit for it.
Why throw away all that hard work you did to write the project? Check your
submittals. Make sure they work. Do this before the due date.
Documentation for the submit program is on the web at http://www.gl.umbc.edu/submit/. The
class name is cs341 and the project name is Proj1. One of the tools provided by
the submit program is submitls.
It lists the names of the files you have submitted.
Project grading is described in the Project
Policy handout.
Cheating in any form will not be tolerated. Please re-read the Project
Policy handout for further details on honesty in doing projects for this
course.
Remember, the due date is firm. Submittals made after midnight of the due
date will not be accepted. Do not submit any files after that time.