|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectstockportfolio.Portfolio
A portfolio represents stocks that are owned. The portfolio remembers the name of each share (or group of shares) and its purchase price. The order in which the stocks are purchased is remembered so that a "oldest sold first" calculation can be made for capital gain when a stock is sold. It is assumed that stocks are added to the portfolio in the order they are purchased and this order never changes. The stock added in a single buy operation constitutes a "block". The portfolio remembers these blocks and deletes them only when a full block's worth of stock is sold. A block is never split up or combined with another block. HOWEVER, if a stock sale only uses part of a block, a new block is created to hold the remaining shares; such a block has the same date and price per share as the original. The fact that it has the same date implies it has the same order as the original block -- it does NOT go to the rear of the queue.
Constructor Summary | |
Portfolio()
Create a new, empty portfolio. |
Method Summary | |
boolean |
buy(java.lang.String stock,
java.util.Date date,
double shares,
double pricePerShare)
Add a block of stock to the portfolio. |
java.util.List |
getBlocksOwned()
Return a list of all the blocks of stock that are owned. |
double |
getSharesOwned(java.lang.String stock)
Tells the number of shares owned of a particular stock. |
double |
sell(java.lang.String stock,
java.util.Date saleDate,
double shares,
double pricePerShare)
"Sell" a block of a stock, in the process calculating the capital gain on the stock. |
java.lang.String |
toString()
Gives a compact summary of the information in the Portfolio. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public Portfolio()
Method Detail |
public java.lang.String toString()
toString
in interface IPortfolio
public boolean buy(java.lang.String stock, java.util.Date date, double shares, double pricePerShare)
IPortfolio
buy
in interface IPortfolio
stock
- a non-null stockdate
- a non-null date/time. You may assume for now that each
block is at a later date/time than any previous block bought.shares
- a number of shares, must be > 0.pricePerShare
- price of each share, must be > 0.
public java.util.List getBlocksOwned()
IPortfolio
getBlocksOwned
in interface IPortfolio
public double getSharesOwned(java.lang.String stock)
IPortfolio
getSharesOwned
in interface IPortfolio
stock
- a non-null stock.
public double sell(java.lang.String stock, java.util.Date saleDate, double shares, double pricePerShare)
IPortfolio
sell
in interface IPortfolio
stock
- non-null stock being sold; must be a stock currently owned.saleDate
- non-null date of the sale.shares
- number of shares being sold, must be >= 0.pricePerShare
- price of each share, must be >= 0.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |