Class Stock

java.lang.Object
  extended by Stock

public class Stock
extends java.lang.Object

Represents a stock in the SafeTrade project


Constructor Summary
Stock(java.lang.String symbol, java.lang.String name, double price)
          Constructs a new stock with a given symbol, company name, and starting price.
 
Method Summary
 java.lang.String getQuote()
          Returns a quote string for this stock.
 void placeOrder(TradeOrder order)
          Places a trading order for this stock.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Stock

public Stock(java.lang.String symbol,
             java.lang.String name,
             double price)
Constructs a new stock with a given symbol, company name, and starting price. Sets low price, high price, and last price to the same opening price. Sets "day" volume to zero. Initializes a priority qieue for sell orders to an empty PriorityQueue with a PriceComparator configured for comparing orders in ascending order; initializes a priority qieue for buy orders to an empty PriorityQueue with a PriceComparator configured for comparing orders in descending order.

Parameters:
symbol - the stock symbol.
name - full company name.
price - opening price for this stock.
Method Detail

getQuote

public java.lang.String getQuote()
Returns a quote string for this stock. The quote includes: the company name for this stock; the stock symbol; last sale price; the lowest and highest day prices; the lowest price in a sell order (or "market") and the number of shares in it (or "none" if there are no sell orders); the highest price in a buy order (or "market") and the number of shares in it (or "none" if there are no buy orders). For example:
 Giggle.com (GGGL)
 Price: 10.00  hi: 10.00  lo: 10.00  vol: 0
 Ask: 12.75 size: 300  Bid: 12.00 size: 500
 Or:
 
 Giggle.com (GGGL)
 Price: 12.00  hi: 14.50  lo: 9.00  vol: 500
 Ask: none  Bid: 12.50 size: 200

Returns:
the quote for this stock.

placeOrder

public void placeOrder(TradeOrder order)
Places a trading order for this stock. Adds the order to the appropriate priority queue depending on whether this is a buy or sell order. Notifies the trader who placed the order that the order has been placed, by sending a message to that trader. For example:
 New order:  Buy GGGL (Giggle.com)
 200 shares at $38.00
Or:
 New order:  Sell GGGL (Giggle.com)
 150 shares at market
Executes pending orders by calling executeOrders.

Parameters:
order - a trading order to be placed.