import java.io.*;
import java.util.*;


/**
 * Reads a data file containing either stock information or commodity
 * futures information and calculates a moving average.
 *
 * @version 1.0
 * @author  Prof. David Bernstein9, James Madison University
 */
 public class Driver
 {


    /**
     * The entry point of the application
     *
     * @param args   The array of command-line arguments
     */
     public static void main(String[] args)
     {
	  		BufferedReader  	myBufferedReader;
			int               securityType;
			SecurityQuotation mySecurityQuotation;
			SecurityReader    mySecurityReader;    
			String            myFileName, securityName;
			TickerSymbol      symbol;

	// Check the number of command-line arguments
	//
	if (args.length < 2) 
	{
	    System.out.println("Too few arguments!");
	    System.exit(1);
	}

	// Process the security name command-line argument
	//
		securityName = args[0].toUpperCase();


	// Process the security type command-line argument
	//
		securityType = -1;
		if (args[1].equals("stk")) 
		{
		    securityType = TickerSymbol.STOCK;

		} 
		else 
			if (args[1].equals("fut")) 
			{
			    securityType = TickerSymbol.FUTURE;
			} 
			else 
			{
			    System.out.println("Bad security type!");
	    		 System.exit(2);
			}
	

	// Setup the file name and TickerSymbol
	//
			myFileName = args[0] + "." + args[1];
			symbol = new TickerSymbol(args[0], securityType);
	
			try 
			{
	  		    	// Create the BufferedReader
	   		 	//
	    		myBufferedReader = new BufferedReader(new FileReader(myFileName));


			    	// Create the SecurityReader
	 		    	//
	    		if (securityType == TickerSymbol.FUTURE)
		 		{
					mySecurityReader = new FutureReader(myBufferedReader, symbol);
			   } 
				else 
				{
					mySecurityReader = new StockReader(myBufferedReader, symbol);
			   }


	  					  // Read and print
	    				  //
	    		mySecurityReader.readAndPrintSecurities();
	    		System.out.println("\n");

			} 
			catch (Exception exception) 
			{
			    System.out.println(exception);
			}
    }

} // end Driver
