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 2.0
 */
public class FutureQuotation extends SecurityQuotation
{
    protected int              openInterest;
    protected String           commodity, month, year;


    /**
     * 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;
    }

//[constructor
    /**
     * Set the attributes of this FutureQuotation 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 FutureQuotation(String commodity, String year, String month,
                                      String s) 
        throws NoSuchElementException, NumberFormatException
    {
        super(s);

        StringTokenizer tokenizer;
        tokenizer = new StringTokenizer(s, ",");
        for (int i=0; i<6; i++) tokenizer.nextToken();

        this.openInterest = Integer.parseInt(tokenizer.nextToken());

        this.commodity = commodity;
        this.year = year;
        this.month = month;
    }
//]constructor

    /**
     * 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);
    }

}
