May 2021 1 120 Report
currency converter in java?

Design a currency Converter class whose object will handle conversion of three currencies (Dollar, Ringgit, Pound). A single object of the new currency Converter class you design here will handle all these three currencies. Instead of having specific conversion methods such as toDollar, toPound and so forth, the new currency Converter class supports one generic conversion method call exchange. The method has three arguments: fromCurrency, toCurrency and amount. The first two arguments are String and give the names of currencies. The third argument is the amount that need to be converted.

To set the exchange rate for a currency, we use the setRate method. This method takes three arguments. The first two arguments are the currency names, and the third argument is the rate.

In addition, the class also have the following method:

updateRate (“fromCurrency”, “toCurrency”, newRate) - The first two arguments are the currency names, and the third argument is the new exchange rate.

Finally, test your program by creating its object in the main() method.


Please enter comments
Please enter your name.
Please enter the correct email address.
You must agree before submitting.

Answers & Comments




Helpful Social

Copyright © 2024 Q2A.MX - All rights reserved.