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:
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.
name symbol type buyingPrice shares floorSellingPrice ceilingSellingPrice info
The value of the info field depends on the type of fund:
Here's an example of portfolio.txt, you can use this to test your programs:
Parse a line of portfolio.txt into the individual fields using Java classes
Scanner
or StringTokenizer.
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
Your program should open and input file portfolio.txt and prompt the user:
Choose:
update prices: u
sell: s:
quit: q
==>
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
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%
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.
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
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.
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.