Coders Packet

Real time currency converter in Java

By Nidali Jaiswal

This code demonstrates the use of external APIs, HTTP requests, JSON parsing, and basic input/output operations in Java to create a currency converter application.

The code begins by importing necessary libraries, including the OkHttpClient from the OkHttp library for making HTTP requests, and the JSONObject from the JSON library.

The CurrencyConverter class is defined within the CurrencyConverter package.

 the main method, the program prompts the user to input the currency codes to convert from and to, along with the quantity to convert.

The API URL is constructed using the base currency provided by the user.

OkHttpClient is created to make HTTP requests. A Request object is constructed with the API URL.

The request is executed using client.newCall(request).execute(), and the JSON response is parsed using the JSONObject class.

The exchange rates for different currencies are extracted from the JSON response.

The currency conversion is performed by multiplying the exchange rate with the quantity. The converted amount is displayed on the screen along with the target currency.

We used this API for taking current exchange rates      "https://api.exchangerate.host/latest";Real time currency converter in Java Output

 

 

Download Complete Code

Comments

No comments yet

Download Packet

Reviews Report

Submitted by Nidali Jaiswal (Nidali)

Download packets of source code on Coders Packet