// CurrencyConverter1.java
// A program which converts US Dollars into British Pounds.

import java.util.Scanner;

public class CurrencyConverter1
{
    // number of currencies
    public static final int NUM_CURRENCIES      = 6;
    // constants to define currencies
    public static final int US_DOLLAR           = 0;
    public static final int BRITISH_POUND       = 1;
    public static final int EURO                = 2;
    public static final int JAPANESE_YEN        = 3;
    public static final int SINGAPORE_DOLLAR    = 4;
    public static final int CHINESE_YUAN        = 5;
    // conversion rates from US dollars to the other five currencies
    public static final float USD_TO_BRITISH_POUND      = 0.630f;
    public static final float USD_TO_EURO               = 0.744f;
    public static final float USD_TO_JAPANESE_YEN       = 82.996f;
    public static final float USD_TO_SINGAPORE_DOLLAR   = 1.289f;
    public static final float USD_TO_CHINESE_YUAN       = 6.584f;

    // function converts money to/from various currencies
    public void convertMoney()
    {
        Scanner input = new Scanner(System.in);
        System.out.print("Enter the amount of US dollars to convert: $");
        float usd = input.nextFloat();
        if (usd >= 0.f)
        {
            float otherCurrencyAmnt = usdToOtherCurrency(usd, BRITISH_POUND);
            printConversionStatement(usd, US_DOLLAR, otherCurrencyAmnt,
                BRITISH_POUND);
        }
        else
        {
            System.out.printf("ERROR: invalid monetary amount! (%1.2f)\n", usd);
        }
    }
    
    // print a statement about the currency conversion
    public void printConversionStatement(float amount1, int currency1,
        float amount2, int currency2)
    {
        System.out.printf("%1.2f %s is equal to %1.2f %s.\n",
            amount1, getCurrencyText(currency1),
            amount2, getCurrencyText(currency2));
    }
    
    // retrieve the string equivalent of each currency
    public String getCurrencyText(int currency)
    {
        switch (currency)
        {
            case US_DOLLAR:
                return "US Dollars";
            case BRITISH_POUND:
                return "British Pounds";
            default:
                return null;
        }
    }
    
    // converts and returns the value of usd in another currency
    public float usdToOtherCurrency(float usd, int otherCurrency)
    {
        switch (otherCurrency)
        {
            case BRITISH_POUND:
                return usd * USD_TO_BRITISH_POUND;
            default:
                return -1.f;
        }
    }
    
    // main method
    public static void main(String[] args)
    {
        CurrencyConverter1 converter = new CurrencyConverter1();
        converter.convertMoney();
    }
}