/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//  Program Name:Converter.java
//  Programmer: John Healy
//  Date: Mar 08 2004
//  Version 1.0
//  Description:  set some verables to a value and set some string values
//                desplay everything to standard out
//
//  Created by Little John on Mon Mar 08 2004.
//  Copyright (c) 2004 Little John's Software. All rights reserved.
// ---------------------------------------------------------------------
// Programmer: John Healy
// Date: Mar 18 2004
// Version: 2.0
// Description:  a window is created and input is receved from the
//               keyboard.  looping is done on having a valid input and
//               the contune question.  a caculation is made from the
//               recieved inputs from the keyboard and the answer is
//               then sent back to the window.
// ---------------------------------------------------------------------
// Programer:John healy
// Date: Mar 24 2004
// version: 3.0
// discription:  use an array.
//----------------------------------------------------------------------
//  Programmer : John Healy
//  Date: Apr 02 2004
//  Descroption :  (1) change name of file from Converter.java to ExchangeStore.java
//                 (2) use a class that was created.
//                 (3) use the created class in an array.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
import java.text.*;
import javax.swing.*;
public class ExchangeStore {
    public static void main (String [] args)
    {

        double answer = 0.0;
        double convertAmount = 0.0;

        int menuChoice = 0;


        Changer[]  moneyExchange = new Changer[6];
		  // Before you can use the array you have to instantiate an instance of changer[]
		  // and store it into your array element
        // moneyExchange[1] = new changer("Philippines Pesos",0.0178635);
		  // Then you can call the method associated with this instance
        // moneyExchange[1].setVars("Philippines Pesos", 0.0178635);  Which of course is not necessary
		  // since it is already initialized by calling the constructor.
		  // See example code for EmployeeIndex

        moneyExchange[1] = new Changer("Philippines Pesos",0.0178635);
        moneyExchange[2] = new Changer("Australia Dollars",0.762615);
        moneyExchange[3] = new Changer("Russia Rubles",0.3505080);
        moneyExchange[4] = new Changer("Zambia Kwacha",0.000210526);
        moneyExchange[5] = new Changer("United Kindom Pounds",1.82410);


        String Title = new String("Currrency Converter \n");
        String[] menu = new String[6];
        String convertAmountS = new String("The convrted amout is :");
        String stringOut = new String("x");
        String eMessage1 = new String("You entered incorrect information.  Please try again");
        String eMessage2 = new String("You entered a value less then Zero. Please try again.");
        String convertQuestion = new String("How much money do you wish to convert? $");
        String yesNo = new String("x");
        String ynQuestion = new String("Do you wish to contune? (Y/N)");
        String thanks = new String("Thank You for using the money converter.");

        for (int I = 1; I < 6; I++)
             menu[I] = "Enter " + I + " To convert " + moneyExchange[I].getName() + "to USD. \n";

        //System.out.println(stringOut);
        NumberFormat money = NumberFormat.getCurrencyInstance();
        do
        {
             do
             {
                 stringOut = Title + menu[1] + menu[2] + menu[3] + menu[4] + menu[5];
                 menuChoice = Integer.parseInt(JOptionPane.showInputDialog(null,stringOut));
                 if(!(menuChoice > 0 && menuChoice <6))
                 {
                     stringOut = eMessage1;
                     JOptionPane.showMessageDialog(null,stringOut);
                  }//end if

             }while(!(menuChoice > 0 && menuChoice <6)); //end while !(fi > 0 && fi <6)
             do
             {
                 stringOut = convertQuestion;
                 convertAmount = Double.parseDouble(JOptionPane.showInputDialog(null,stringOut));
                 if(!(convertAmount > 0))
                 {
                    stringOut = eMessage2;
                    JOptionPane.showMessageDialog(null,stringOut);
                  }//end if
             }while (!(convertAmount > 0)); //end do---while !(fum > 0)
                stringOut = convertAmountS + money.format(moneyExchange[menuChoice].getFactor() * convertAmount);
                JOptionPane.showMessageDialog(null,stringOut);
                stringOut = ynQuestion;
                yesNo  = JOptionPane.showInputDialog(null,stringOut);
        }while(yesNo.equals("y") || yesNo.equals("Y"));// end do -- while yesNo != "y" || yesNo != "Y"
        stringOut = thanks;
        JOptionPane.showMessageDialog(null,stringOut);
        System.exit(0);


    }//end main
} // end class


