import java.util.*;


/**
 * A future's contract quotation (i.e., open, high, low, close,
 * volume, and open interest).
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 3.0
 */
public class FutureQuotation extends SecurityQuotation
{
    protected int              openInterest;
    protected String           commodity, month, year;

//[constructor
    /**
     * Default Constructor.
     *
     * Normally, the use of this constructor is followed immediately
     * by a call to fromString() to set the attributes.
     */
    protected FutureQuotation()
    {
        super();
    }
//]constructor

    /**
     * Explicit Value Constructor.
     *
     * @param commodity The commodity code
     * @param year      The year code
     * @param month     The month code
     * @param date      The date of the entry
     * @param open      The opening price
     * @param high      The high price
     * @param low       The low price
     * @param close     The closing price
     * @param volume    The volume traded
     */
    public FutureQuotation(String commodity, String year, String month, 
                           GregorianCalendar date, 
			   double open,double high,double low,double close,
                           int volume, int openInterest)
    {
	super(date, open, high, low, close, volume);

        this.commodity    = commodity;
        this.year         = year;
        this.month        = month;
	this.openInterest = openInterest;
    }


//[createInstance    
    /**
     * Parse a String representation of a StockQuotation into 
     * its components and construct a StockQuotation from them.
     *
     * @param s         The String representation
     */
    public static FutureQuotation createInstance(String s) 
                                 throws NoSuchElementException,
                                        NumberFormatException
    {
	FutureQuotation fq;
	fq = new FutureQuotation();
	fq.fromString(s);
	return fq;
    }
//]createInstance
    

//[fromString
    /**
     * Set the attributes of this StockQuotation based on
     * a String representation.
     *
     * @param commodity The commodity code
     * @param year      The year code
     * @param month     The month code
     * @param s         The String representation
     */
    public StringTokenizer fromString(String commodity, String year, String month,
                                      String s) 
        throws NoSuchElementException, NumberFormatException
    {
        String                 token;        
        StringTokenizer        tokenizer;
        
        this.commodity    = commodity;
        this.year         = year;
        this.month        = month;

        tokenizer = super.fromString(s);
        token = tokenizer.nextToken();
        this.openInterest = Integer.parseInt(token);

        return tokenizer;
    }
//]fromString

    /**
     * Return the open interest for this security.
     *
     * @return  The open interest
     */
    public int getOpenInterest()
    {
        return openInterest;
    }

    /**
     * Return the symbol for this security.
     *
     * @param symbol     The ticker symbol for this stock
     */
    public String getSymbol()
    {
        return commodity + year + month;        
    }

    /**
     * Return a String representation.
     *
     * @return   The String representation
     */
    public String toString()
    {
	return (super.toString()+"\tOI: " + openInterest);
    }
}
