- Google provides a Currency Converter API services for Consumption by Client Application.
- The link for this library is listed below:-
- The maven dependecy tag to include this library is listed below.
<dependency>
<groupId>com.tunyk.currencyconverter</groupId>
<artifactId>currency-converter-api</artifactId>
<version>1.0</version>
</dependency>
- In this Demo, “We will see how to configure it in a Java project with a simple currency conversion”.
- The source code can be checked out from the repository through SVN checkout.The link for the source is listed below:-
- The it can be converted to JAR file using maven build and package.The command or batch file for build is listed below:-
mvn clean package javadoc:jar javadoc:test-jar source:jar source:test-jar site:jar
- Then currency-converter-api-1.0.jar file will be generated from the above build.
- The depended JAR files to be included in the project are ehcache-core-2.4.3.jar,log4j-1.2.14.jar,slf4j-api-1.5.10.jar,slf4j-log4j12-1.5.10.jar.
- The Project will look like below screenshot after configuring depended JAR.
- The Java code is present in CurrencyConverterDemo.java file and the code is listed below.
package com.google.ts;
import com.tunyk.currencyconverter.api.Currency;
import com.tunyk.currencyconverter.api.CurrencyConverterException;
import com.tunyk.currencyconverter.BankUaCom;
import com.tunyk.currencyconverter.api.CurrencyConverter;
public class CurrencyConverterDemo {
public static void main(String[] args) {
try {
CurrencyConverter currencyConverter = new BankUaCom(Currency.USD, Currency.EUR);
Float inEuro = currencyConverter.convertCurrency(1f);
System.out.println("1 USD = "+inEuro+" Euro");
} catch (CurrencyConverterException e) {
e.printStackTrace();
}
}
}
- The output will come in the Eclipse console and look like below screenshot.It is showing 1 USD is converted to 0.73 Euro.