/**
 * Introduction to OOP with Java 2nd Edition, McGraw-Hill
 *   
 *  Chapter 4
 *
 * <p>
 * This class is used to do the currency conversion 
 * between a foreign currency and the U.S. dollar.
 *
 * @author Dr. Caffeine
 */

class CurrencyConverter
{

//----------------------------------
//    Data Members
//----------------------------------
  
  /**
   * how much $1.00 U.S. is worth in the foreign currency
   */
    private double exchangeRate;  
    
   
//----------------------------------
//    Constructors
//----------------------------------
                                
   /**
    * Default constructor
    */
   public CurrencyConverter( double rate )
   {
       exchangeRate = rate;
   }
   
   
//-------------------------------------------------
//      Public Methods:
// 
//          double  fromDollar        (   double        )
//          void    setExchangeRate   (   double        )
//          double  toDollar          (   double        )
//
//------------------------------------------------
                                
   /**
    * Converts a given amount in dollars into
    * an equivalent amount in a foreign currency.
    * 
    * @param dollar the amount in dollars to be converted
    *
    * @return amount in foreign currency
    */
   public double fromDollar( double dollar )
   {
      return (dollar * exchangeRate);
   }
   
   
   /**
    * Converts a given amount in a foreign currency into
    * an equivalent dollar amount.
    * 
    * @param  foreignMoney the amount in dollars to be converted
    *
    * @return amount in dollar
    */
   public double toDollar( double foreignMoney )
   {
      return (foreignMoney / exchangeRate);
   }
                             
   
   /**
    * Sets the exchange rate to the value passed
    * to this method.
    * 
    * @param rate the exchange rate
    *
    */   
   public void setExchangeRate( double rate )
   {
      exchangeRate = rate;
   }
                   
}                   