CMSC 341 Project 1

Assigned Sept 19, 2012
Due 11:59pm Oct 7, 2012
Points 100




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

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.

  1. Numbers of shares one can buy/sell are integers (int), the tickers are strings, and all other parameters for these commands are real (float).
  2. The cash account should be initialized to zero.
  3. For simplicity, we assume that the price given in BUY and SELL commands are the latest price of the given stock, and they will cause "the latest price" in the portfolio be updated. "The latest price" will also be updated by the SHAREPRICE command.
  4. Since the investor can buy and cumulate the same stock at different time with different share prices, the "purchase share price" need to be recalculated whenever the number of shares of a stock is increased with a new purchase. 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. Note that selling shares of a stock does not change the purchase price for the remaining shares of that stock in the portfolio.
  5. The gain is calculated as ("latest share price" - "purchase share prince") /"purchase share price".
  6. When the number of shares of one stock becomes 0 (zero) after one "sell" transaction, its entry shall be removed from the portfolio.
  7. 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.
  8. 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.


  1. Use CVS to checkout your repository for this project. Your repository is in


    It contains a generic build.xml file that you must modify for this project.
  2. Implement a linked list class, list node class and list iterator class. You are free to create java classes and methods necessary for this project either from scratch or reuse some from, say Java Collection classes or author's code. Use a README file justify your choice. The author's code can be found in Dr. Peng's public directory


    Be be advised that the author's code may require editting before it works perfectly. See the textbook errata sheet.
  3. You must put all classes into a package named proj1 .
  4. Create command file(s) to test your code.
  5. Use CVS to submit and commit all of your source files and your build.xml file. DO NOT submit your .class files.
  6. Use the course cvs utilities to verify that your project will be built and executed correctly by the project grading scripts.

The 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 portfolio in that order. For example

 linux3> java Project1 -Dargs="/afs/"

Here is an example of the command file:

CASHIN 100000
BUY MSFT 20 32.24
BUY BAC 100 42.22
BUY MSFT 10 31.15
SELL BAC 20 43.35
BUY INTC 20 12.75

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.

Sample Output

Sample output can be found here. The sample output was created by this command file.

Grading and Academic Integrity

Project grading is described in the Project Policy handout. Note that proper class and method documentation via javadoc is required.

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.