Menu
Question Index
...

Write a program to convert amount from one currency to another. The exchange rates between various currencies are given.

Input (List, String, double, String) Output (double)
[INR-USD:54.18, JPY-USD:99.079, GBP-USD:0.65], INR, 500.00, USD 27090.0
[INR-USD:54.18, JPY-USD:99.079, GBP-USD:0.65], JPY, 599.00, USD 6.04568
[INR-USD:54.18, JPY-USD:99.079, GBP-USD:0.65], USD, 300.00, INR 5.5371
[CNY-USD:6.16, EUR-USD:0.77, LKR-USD:126.8, USD-GBP:1.55], USD, 152.00, CNY 936.32
[CNY-USD:6.16, EUR-USD:0.77, LKR-USD:126.8, USD-GBP:1.55], EUR, 1500.00, USD 1948.05195
[CNY-USD:6.16, EUR-USD:0.77, LKR-USD:126.8, USD-GBP:1.55], USD, 15.00, LKR 1902.0
[CNY-USD:6.16, EUR-USD:0.77, LKR-USD:126.8, USD-GBP:1.55], GBP, 25.00, USD 38.75


import java.util.*;
class ExchangeCurrency
{
    public static void main(String s[])
    {
        List<ExchangeRate> exchangeRates = new ArrayList<ExchangeRate>();
        exchangeRates.add(new ExchangeRate("INR", "USD", 54.18));
        exchangeRates.add(new ExchangeRate("JPY", "USD", 99.13));
        exchangeRates.add(new ExchangeRate("CNY", "USD", 6.16));
        double rupees = exchange(exchangeRates, "USD", 500.0, "INR");
        System.out.println("500 USD is same as " + rupees + " INR");

    }


    public static double exchange(List<ExchangeRate> exchangeRates, String sourceCurrency, double amount, String targetCurrency) {
    }

}
class ExchangeRate {

String targetCurrency;
String baseCurrency;
double rate;

public ExchangeRate(String targetCurrency, String baseCurrency, double rate) {
this.targetCurrency = targetCurrency;
this.baseCurrency = baseCurrency;
this.rate = rate;
}

@Override
public String toString() {
return targetCurrency + "-" + baseCurrency + ":" + rate;
}
}

Doubts

Problems

Topic: Java ArrayList

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App