CS 211
Project 4
due May 3, 2010

Program

Write a program to keep track of an investment portfolio.

Portfolio information is read from a file. Your program reads in information about each stock or bond mutual fund in the portfolio, computes the current profit, and issues a "hold" or "sell" recommendation for each fund. (See the sample execution below.)

Fund data is stored in a file called portfolio.txt. The data is in the format:

 name symbol type buyingPrice shares floorSellingPrice ceilingSellingPrice info
where the name is one word and the symbol is one word. The type is either stock, bond, or cash. A portfolio has only one cash fund.

The value of the info field depends on the type of fund:

If a stock or bond fund's share price reaches a value that is less than the floorSellingPrice or higher than the ceilingSellingPrice, a "sell" recommendation should be given. A bond fund's share price fluctuates with changes in interest rates for comparable investments. The share price of a cash fund is $1.00 and it never changes (we hope).

Here's an example of portfolio.txt, you can use this to test your programs:

  VanguardTotalBondMarketIndexFund VBMFX bond 10.41 1000 10.00 11.00 3.18
  VanguardTotalStockMarketIndexFund VTSMX stock 29.70 1000 29.00 30.50 blend
  VanguardSmallCapIndexFund NAESX stock 31.26 1000 31.00 32.00 smallcap
  VanguardEmergingMarketsStockIndexFund VEIEX stock 27.52 1000 27.00 28.00 international
  VanguardPrimeMoneyMarketFund VMMXX cash 1.00 50000 0.00 9999.00 .01
Parse a line of portfolio.txt into the individual fields using Java classes Scanner or StringTokenizer.

Your program should open and input file portfolio.txt and prompt the user:

Choose:
update prices: u
sell: s:
quit: q
==>

If the user selects 'u':

For each non-cash fund in the portfolio, prompt the user for the current share price. Based on the buying price, the number of shares owned, and the current share price, compute the profit for the fund. (The profit may be negative). Compare the current price to the floor and ceiling selling prices. If the current price is lower than the floor selling price, or higher than the ceiling selling price, issue a "sell" recommendation. Otherwise, issue a "hold" recommendation.

Sample Execution:

                 Portfolio Manager

Choose:
update Prices: u
sell: s:
quit: q
==> u

Enter the current price for VanguardTotalBondMarketIndexFund (VBMFX): 10.41
Enter the current price for VanguardTotalStockMarketIndexFund (VTSMX): 29.70 
Enter the current price for VanguardSmallCapIndexFund (NAESX): 31.26
Enter the current price for VanguardEmergingMarketsStockIndexFund (VEIEX): 27.52

VanguardTotalBondMarketIndexFund (VBMFX)
buying price: $10.41, shares: 1000, current price: $10.41 floor selling price: $10.00 ceiling selling price: $11.00 yield: 3.18%
==> profit: $0.00
HOLD

VanguardTotalStockMarketIndexFund (VTSMX)
buying price: $29.70, shares: 1000, current price: $29.70 floor selling price: $29.00 ceiling selling price: $30.50 type: blend
==> profit: $0.00
HOLD

VanguardSmallCapIndexFund (NAESX)
buying price: $31.26, shares: 1000, current price: $31.26 floor selling price: $31.00 ceiling selling price: $32.00 type: smallcap
==> profit: $0.00
HOLD

VanguardEmergingMarketsStockIndexFund (VEIEX)
buying price: $27.52, shares: 1000, current price: $28.10 floor selling price: $27.00 ceiling selling price: $28.00 type: international
==> profit: $580.00
SELL

Total Profit: $580.00

If the user selects 's':

Prompt the user for the fund name, the number of shares to sell (an integer), and the current price of the fund. The money for the sold shares is deposited into the cash fund. Update the cash fund value and update the fund information for the fund whose shares were sold.

Sample Execution:

                 Portfolio Manager

Choose:
update Prices: u
sell: s:
quit: q
==> s

Enter Fund: VanguardSmallCapIndexFund
Number of shares to sell: 100
Current Price: $31.26

VanguardSmallCapIndexFund (NAESX)
buying price: $31.26, shares: 900, floor selling price: $31.00 ceiling selling price: $32.00 type: smallcap
Cash: $53126.00, yield: .01%

Requirements

Your program will use 5 classes and 1 interface.

Portfolio class:
   an array (or ArrayList, or LinkedList) of stock and bond fund Investment objects (see class Investment below)
   a cash Investment object (see class Investment below)
methods:
   a default constuctor
   method inputPortfolio: read portfolio data file 
   method getCurrentPrices: prompt user for current fund prices
   method computeProfit:  compute total profit for stock and bond funds.
   method displayAnalysis: display hold/sell recommendations for investments

Investment class: an abstract class - some of the methods in this class may be abstract too, e.g., display
    name (String)
    symbol (String)
    type (Enumeration) Nordstrom's section may use String here
    buyingPrice (double)
    currentPrice (double)
    sharesBought (int)
    floorSellingPrice (double)
    ceilingSellingPrice (double)
    profit (double)
methods:
    constructor(s)
    getName and setName
    getSymbol and setSymbol
    getType and setType
    getBuyingPrice and setBuyingPrice
    getCurrentPrice and setCurrentPrice
    getSharesBought and setSharesBought
    getFloorSellingPrice and setFloorSellingPrice
    getCeilingSellingPrice and setCeilingSellingPrice
    computeProfit: compute the profit
    getProfit
    display: display the fund data

StockFund class inherits from Investment and implements interface Sellable (see below)
    enumeration StockType : smallcap, mediumcap, largecap, blend, international
methods:
    constructor(s)
    getStockType and setStockType
    display: display the fund data
    sell: parameter is number of shares to sell

BondFund class inherits from Investment and implements Sellable
    yield
methods:
    constructor(s)
    getYield and setYield
    display: display the fund data
    sell: parameter is number of shares to sell

CashFund class inherits from Investment
    yield
methods:
    constructor(s)
    getYield and setYield
    display: display the fund data
If a line of data in the portfolio file contains information about a stock fund then a StockFund object should be created to hold that data; likewise for a bond fund. CashFund objects are created for cash funds.

Interface Sellable has a single method:
     public void sell(int shares);

Function main() will open the portfolio data file, declare a Portfolio object, read in the portfolio data, and prompt for and respond to the user's choices.

Useful Links

Here are some links to some Java classes that are useful for this assignment:

Scanner

Console

StringTokenizer

List

LinkedList

ArrayList

Submit the following:

- your source code,

- a sample terminal session of your application, and

- a statement of which parts of the assignment (if any) are incomplete or known to be incorrect.

For the terminal session, use the portfolio data file that is posted. A list of commands to use for your terminal session will be posted.