Last Revised 7/2/03 at 11:30pm.

CSC 211 -- Currency Project -- 100 Points

Goal: Write a Java program that will convert money from one currency to another. Use these exchange rates (valid on 4/23/03):

Currency Amount per $
Dollar 1.000
Euro 0.907
Krona 8.264
Peso 10.446
Pound 0.629
Yen 119.8

Your program should display three consecutive input dialogs something like this:

   

The Terminal Window of your program should be something similar to this:

Source currency is Yen.
Target currency is Euro.
Source amount is 5000.00.
Target amount is 37.855.

To terminate the program, click cancel.

Optional:   Write a static method named getRate that inputs the name of the currency and returns the conversion rate (amount per dollar). Here is the header:

public static double getRate(String currencyName)

Use an if..else statement that starts like this:

if (currencyName.equals("dollar"))
    return 1.000;
else if (currencyName.equals("euro"))
    return 0.907;
// etc........
else     return 1.000;
Note: do not use the == operator to compare strings. Use the String equals method instead.

Hints for writing the main method:

  • Use this formula to convert from the source to the target amount:
    targetAmount = sourceAmount * targetRate / sourceRate

  • Use a while statement to keep processing transactions until the user clicks Cancel in the input dialog for Source Currency.

  • Use a DecimalFormat object to round the source and target amounts to three decimal places.

  • Here is suggested pseudocode:

    Declare variables.
    Display input dialog for sourceCurrency.
    while (sourceCurrency != null)
    {
        Display input dialog for targetCurrency.
        Display input dialog for sourceAmount.
        Convert the sourceAmount to a double.
        Get sourceRate from sourceCurrency using if..else statements.
        Get targetRate from targetCurrency using if..else statements.
        Use formula to compute targetAmount.
        Format targetAmount using DecimalFormat object.
        Print result in terminal window.
        Display input dialog for sourceCurrency.
    }