/**
 *
 * Class Currency 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.04.2002
 *
 */

import java.io.*; 
import java.lang.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Currency {

	/* two-dimensional array that is the original source of data */
  	static double[][] sdSource = {
    		{ 1.0, 0.700035, 1.5919, 1.14771, 1.93556 }, 
		{ 1.4285, 1.0, 2.27402, 1.6395, 2.76466 }, 
		{ 0.62818, 0.439748, 1.0, 0.720968, 1.21575 }, 
		{ 0.8713, 0.60994, 1.38702, 1.0, 1.68627 }, 
		{ 0.516699, 0.361707, 0.822534, 0.593021, 1.0 }, 
	};

	/* data file */
	protected static String strDataFile;

	/* rows, columns and counters */
	protected static int nRow = 5;
	protected static int nCol = 5;
	protected static int nI, nJ;

	/* dialog */
	protected static JDialog jdCurrDialog;

	/**
	 *
	 * method main begins the process by writing the data to a file
	 * and reading the file's contents to a two-dimensional array.
	 * @param  args[] - String - command line argument
	 * @return none
	 *
	 */
	public static void main(String args[]) {
		if (args.length > 0) {
			strDataFile = args[0];
			Currency currC = new Currency(strDataFile);
		} else {
			System.out.println("To correctly run the application, type:  ");
			System.out.println("java Currency data_file");
			System.out.println("Where data_file is the name of the data file.");
		}
	}

	/**
	 *
	 * Currency is the constructor method for the Currency class.
	 * It takes in the data file as the parameter and writes the
	 * data to the data file.  It also shows the Dialog for the
	 * application.
	 * @param  strDataFile - String - name of data file
	 * @return none
	 *
	 */
	public Currency(String strDataFile) {
    
   	 	/* writes the data to file */
		try { 
			PrintWriter out = 
				new PrintWriter(
					new BufferedWriter(
						new FileWriter(strDataFile)));
 			for (nI = 0; nI < nRow; nI++) {
				for (nJ = 0; nJ < nCol; nJ++) {
					out.println(sdSource[nI][nJ]); 
				}
 			}
 			out.close(); 
		} catch (IOException e) {}
		
		/* shows the currency dialog screen */
		jdCurrDialog = new CurrencyDialog(Currency.this);
		jdCurrDialog.show();
 	}
}
