CMSC 341 Project 1
|Assigned||Sept 19, 2012|
|Due||11:59pm Oct 7, 2012|
- Sept 30: The package name for this project should be proj1 , not proj2.
The CVS repository path is
- 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.
DescriptionIn 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)
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.
- CASHOUT < 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 in the portfolio.
- 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.
- 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.
- 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.
- 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.
- The gain is calculated as ("latest share price" - "purchase share prince") /"purchase share price".
- When the number of shares of one stock becomes 0 (zero) after one "sell" transaction, its entry shall be removed from the portfolio.
- 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.
- Use CVS to checkout your repository for this project. Your repository is in
/afs/umbc.edu/users/y/p/ypeng/pub/cs341f12/Proj1.It contains a generic build.xml file that you must modify for this project.
- 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
/afs/umbc.edu/users/y/p/ypeng/pub/341/Project1/MyLinkedList.javaBe be advised that the author's code may require editting before it works perfectly. See the textbook errata sheet.
- You must put all classes into a package named proj1 .
- Create command file(s) to test your code.
- Use CVS to submit and commit all of your source files and your build.xml file. DO NOT submit your .class files.
- Use the course cvs utilities to verify that your project will be built and executed correctly by the project grading scripts.
linux3> java Project1 -Dargs="/afs/umbc.edu/users/y/p/ypeng/pub/cs341s08/test/Proj1/test1"Here is an example of the command file:
BUY MSFT 20 32.24
BUY BAC 100 42.22
BUY MSFT 10 31.15
SHAREPRICE BAC 43.35
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.
here. The sample output was created by this command file.
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.