main method that obtains the currency exchange rate for U.S. Dollars (USD) from the
io.fixer website.
Note: the source currency or base currency is Euro (EUR).
Obtain your free access key and insert it into the URL before running this code.
public static void main(String[ ] args)
throws IOException, MalformedURLException {
String prefix = "http://data.fixer.io/api/latest";
String accessKey = "?access_key=<<Insert your access key here>>";
String insert = "&symbols=";
String targetCurrency = "USD";
String urlString = prefix + accessKey + insert + targetCurrency;
System.out.println(urlString);
URL url = new URL(urlString);
Scanner s = new Scanner(url.openStream( ));
String jsonString = s.nextLine( );
System.out.println(jsonString);
int start = jsonString.indexOf(targetCurrency) + 5;
int end = jsonString.length( ) - 2;
System.out.println("start: " + start + " end: " + end);
System.out.println(jsonString.substring(start, end));
s.close( );
}