/*
   Chapter 3:  Programming Assignment 11
   Programmer: Brad Shedd
   Date:       January 15, 2004
   Filename:   CurrencyConversion.java
   Purpose:    Converts an American dollar amount into British pound, euro, or Russian ruble equivalents.
*/

import java.text.*;
import javax.swing.*;

public class CurrencyConversion
{
  
public static void main(String[] args)
   {
     
//constants
      final double POUND_EXCHANGE_RATE = 0.543193;
     
final double EURO_EXCHANGE_RATE = 0.785766;
     
final double RUBLE_EXCHANGE_RATE = 28.88667;

      DecimalFormat twoDigits =
new DecimalFormat("###,###.00");

     
// variables
      String input, output;
     
double dollar, pound, euro, ruble;

      input = JOptionPane.showInputDialog(
null, "Enter a dollar amount:  ");

      dollar = Double.parseDouble(input);

     
//calculations
      pound = dollar * POUND_EXCHANGE_RATE;
      euro = dollar * EURO_EXCHANGE_RATE;
      ruble = dollar * RUBLE_EXCHANGE_RATE;

      output =
"Dollar Amount:  " + twoDigits.format(dollar) +
              
"\nin Pounds:  " + twoDigits.format(pound) +
              
"\nin Euros:  " + twoDigits.format(euro) +
              
"\nin Rubles:  " + twoDigits.format(ruble);

      JOptionPane.showMessageDialog(
null, output, "Currency Conversion", JOptionPane.PLAIN_MESSAGE);

  }
//end main method
}// end CurrencyConversion class


Homepage