CS1007
Fall 2002
Homework #6
due Thu Dec 5, by 6AM -- electronic submission
hardcopy due IN CLASS: 2.45PM

goal.
This is your last homework assignment for cs1007 (yippee!). The goal is to put together many of the pieces we've learned this semester into one program. The description of this program (below) is a more general type of specification than you've had for your previous homeworks. You will have to make many design and implementation decisions yourself, though you can use examples from class to help you get started.
This assignment is worth a total of 11 points.

Note: There will be no extensions on this assignment. The only exception is if you have a DOCUMENTED medical excuse.

specifications.
You need to design and implement software for maintaining a stock portfolio. The program interfaces with two data files. One data file contains data records of the New York Stock Exchange (NYSE). The other data file contains data records of your portfolio.

NYSE data file. Each record in the NYSE data file contains the following fields:

Here is an example:
DeltaAir 11.41 7.21 10.00 +0.55
FootLockr 10.25 9.32 10.25 +1.02
IBM 74.25 62.15 70.00 -4.25
OffcDpt 14.89 12.46 14.89 +2.43
Sears 36.44 22.70 24.16 -8.56

Portfolio data file. The first record in your portfolio data file contains your current amount of cash. The remaining records in the portfolio file represent transactions of stock purchases. The first field in each record contains the name of the stock. The second field contains the number of "buy" transactions for that stock. The remaining fields are grouped in pairs, one pair for each "buy" transaction, and contain the number of shares purchased and the purchase price for each transaction.
Here is an example:

82.46
IBM 2 3 70.0 7 75.34
Sears 1 6 24.16

Your program will be text only (not a GUI), run with a command line interface to a text menu that will allow users the following options:

The program will start by reading the two data files, as described below. Note that any modifications your user makes to each data file must be written back to that data file before the program exits.

After reading in the data files, the program will then continue running by displaying the menu of choices (above), prompting the user to enter a choice, reading the user's choice and processing the user's choice -- until the user decides to quit, at which point the program will update the data files and exit.

You should start your user with $1000 in cash and an empty portfolio file the first time you run the program.

You need to implement a sorting method to display the contents of your portfolio in alphabetical order, according to the name of the stock.

You need to implement a search method to find stocks both in your portfolio and in the NYSE database.

design.
You MUST write a SHORT design document describing your approach to the program. You are strongly encouraged to write an informal flowchart FIRST, to help think through how to design this program. The design document MUST include a description of ALL class files and ALL major data structures (in 500 words or less). Note: This design document will ONLY be submitted in hard copy. Do NOT submit this part electronically.

implementation.
Your program MUST be a Java application. You can use as many class files as you need to, but the main() method MUST be contained in a file called hw6<yourCUNIXusername>.java, e.g., hw6eis2003.java. Don't forget to comment your code!!! Hint: your source code comments must be consistent with your design document!

You must use the standard format for the data files, as described above. Download and use the nyse.dat file provided.

sample run.

unix$ java hw6eis2003
There are 5 stocks in your NYSE
There are 2 different stocks in your portfolio.
You have $82.46 in your account.
IBM  3 shares @ $70.00 7 shares @ $75.34
Sears  6 shares @ $24.16
-----------------------
N (YSE display)
D (isplay my portfolio)
B (uy stocks)
S (ell stocks)
U (pdate stock price)
Q (uit)
-----------------------
enter choice> n
DeltaAir 11.41 7.21 10.00 +0.55
FootLockr 10.25 9.32 10.25 +1.02
IBM 75.34 62.15 75.34 +5.34
OffcDpt 14.89 12.46 14.89 +2.43
Sears 36.44 22.70 24.16 -8.56
-----------------------
N (YSE display)
D (isplay my portfolio)
B (uy stocks)
S (ell stocks)
U (pdate stock price)
Q (uit)
-----------------------
enter choice> u
enter name of stock to update: FootLockr
enter new price: 12
-----------------------
N (YSE display)
D (isplay my portfolio)
B (uy stocks)
S (ell stocks)
U (pdate stock price)
Q (uit)
-----------------------
enter choice> n
DeltaAir 11.41 7.21 10.00 +0.55
FootLockr 12.00 9.32 12.00 +1.75
IBM 75.34 62.15 75.34 +5.34
OffcDpt 14.89 12.46 14.89 +2.43
Sears 36.44 22.70 24.16 -8.56
-----------------------
N (YSE display)
D (isplay my portfolio)
B (uy stocks)
S (ell stocks)
U (pdate stock price)
Q (uit)
-----------------------
enter choice> b
enter name of stock to buy: FootLockr
the current price of this stock is $12.00
how many shares do you want to purchase? 1
-----------------------
N (YSE display)
D (isplay my portfolio)
B (uy stocks)
S (ell stocks)
U (pdate stock price)
Q (uit)
-----------------------
enter choice> d
There are 3 different stocks in your portfolio.
You have $70.46 in your account.
FootLockr  1 shares @ $12.00
IBM  3 shares @ $70.00 7 shares @ $75.34
Sears  6 shares @ $24.16
-----------------------
N (YSE display)
D (isplay my portfolio)
B (uy stocks)
S (ell stocks)
U (pdate stock price)
Q (uit)
-----------------------
enter choice> s
enter name of stock to sell: Sears
the current price of this stock is $24.16
how many shares do you want to sell? 4
-----------------------
N (YSE display)
D (isplay my portfolio)
B (uy stocks)
S (ell stocks)
U (pdate stock price)
Q (uit)
-----------------------
enter choice> d
There are 3 different stocks in your portfolio.
You have $167.10 in your account.
FootLockr  1 shares @ $12.00
IBM  3 shares @ $70.00 7 shares @ $75.34
Sears  2 shares @ $24.16
-----------------------
N (YSE display)
D (isplay my portfolio)
B (uy stocks)
S (ell stocks)
U (pdate stock price)
Q (uit)
-----------------------
enter choice> q
unix$

source code.
Your source code (i.e., your .java file) but be neat and clearly commented. You must have a header comment and you should comment the end of each block (i.e., each }). You need to COMMENT EVERY METHOD that you write within each class.

submission.
As usual, submit your program in two ways: electronically and hard copy.

points.
The assignment is worth 11 points, as follows: