/**
 *
 * Class CurrConvFactory implements a method 
 * that shows the currencies in British pounds, 
 * Canadian dollars, Euros, Australian dollars 
 * and US dollars.
 *
 * @author  Daniel Burgner
 * @version 1.0
 * @class   CS5730
 * @date    03.05.2002
 *
 */

import java.io.*;
import java.lang.*;

public class CurrConvFactory 
	implements CurrFactory {

	/**
	 * method makeConversion makes the conversions for the
	 * respective currencies and stores them in Conversion
	 * array.
	 * @param  strCurr - String - type of Currency
	 * @return Conversion[] - array of Conversion
	 *
	 */
	public Conversion[] makeConversion(String strCurr) {

		String strLine;				// line of data
		String strDF = currC.strDataFile;	// data file
		int nRow = 5;
		int nCol = 5;
		Conversion cConvArray[];		// Conversion array

		/* array of conversion rates as doubles */
		double dData[][] = new double[nRow][nCol];

		/* reads the data from file and stores data into array */
		try {
			BufferedReader in =
				new BufferedReader(new FileReader(strDF));

			for (int nI = 0; nI < nRow; nI++) {
				for (int nJ = 0; nJ < nCol; nJ++) {
					strLine = in.readLine();
					dData[nI][nJ] =
						Double.valueOf(strLine).doubleValue();
				}
			}
		} catch (IOException e) {}

		/* initializes array of Conversions */
		cConvArray = new Conversion[nRow];

		/* stores array of conversion rates according to type */
		if (strCurr.equals("USD")) {
			cConvArray[0] = new USDGBP(1.0);
		 	cConvArray[1] = new USDGBP(dData[0][1]);
			cConvArray[2] = new USDCAD(dData[0][2]);
		 	cConvArray[3] = new USDEUR(dData[0][3]);
		 	cConvArray[4] = new USDAUD(dData[0][4]);
		} else if (strCurr.equals("GBP")) {
			cConvArray[0] = new USDGBP(dData[0][1]);
			cConvArray[1] = new USDGBP(1.0);
		 	cConvArray[2] = new GBPCAD(dData[1][2]);
		 	cConvArray[3] = new GBPEUR(dData[1][3]);
		 	cConvArray[4] = new GBPAUD(dData[1][4]);
		} else if (strCurr.equals("CAD")) {
		 	cConvArray[0] = new USDCAD(dData[0][2]);
		 	cConvArray[1] = new GBPCAD(dData[1][2]);
			cConvArray[2] = new USDGBP(1.0);
		 	cConvArray[3] = new CADEUR(dData[2][3]);
		 	cConvArray[4] = new CADAUD(dData[2][4]);
		} else if (strCurr.equals("EUR")) {
		 	cConvArray[0] = new USDEUR(dData[0][3]);
		 	cConvArray[1] = new GBPEUR(dData[1][3]);
		 	cConvArray[2] = new CADEUR(dData[2][3]);
			cConvArray[3] = new USDGBP(1.0);
		 	cConvArray[4] = new EURAUD(dData[3][4]);
		} else if (strCurr.equals("AUD")) {
		 	cConvArray[0] = new USDAUD(dData[0][4]);
		 	cConvArray[1] = new GBPAUD(dData[1][4]);
		 	cConvArray[2] = new CADAUD(dData[2][4]);
		 	cConvArray[3] = new EURAUD(dData[3][4]);
			cConvArray[4] = new USDGBP(1.0);
		}
		return cConvArray;
	}

	protected Currency currC;	// Currency representation
	
	/**
	 *
	 * CurrConvFactory is the constructor method for the
	 * CurrConvFactory class.  All it does is it takes in
	 * a Currency parameter and stores it into a similar
	 * data member.
	 * @param  currC - Currency - Currency representation
	 * @return none
	 *
	 */
	public CurrConvFactory(Currency currC) {
		this.currC = currC;
	}
}
