October 19, 2017

Java Real Time currency convertor

import java.io.IOException;



/**
 *
 */

/**
 * @author belazy
 *
 */
public class CurrencyConvertor {

   public float convert(String currencyFrom, String currencyTo) throws IOException {
        HttpClient httpclient = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet("http://quote.yahoo.com/d/quotes.csv?s=" + currencyFrom + currencyTo + "=X&f=l1&e=.csv");
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String responseBody = httpclient.execute(httpGet, responseHandler);
        httpclient.getConnectionManager().shutdown();
        return Float.parseFloat(responseBody);
    }

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

CurrencyConvertor cc = new CurrencyConvertor();
try {
            float current = cc.convert("USD", "AED");
            System.out.println(current);
        }
        catch (Exception e) {
            e.printStackTrace();
        }

}

}

No comments:

Post a Comment

Your feedback may help others !!!

Facebook comments