import java.util.HashMap; public class CurrencyConverter { HashMap rates = new HashMap<>(); public CurrencyConverter() { rates.put("USD", 1.00); rates.put("EUR", 0.94); rates.put("GBP", 0.82); rates.put("INR", 68.32); rates.put("AUS", 1.35); rates.put("CAN", 1.32); rates.put("SGD", 1.43); rates.put("CHF", 1.01); rates.put("MYR", 1.01); rates.put("YEN", 1.01); rates.put("CNY", 6.92); } public double convertTo(String base, String convert, double value) { double baseRate = rates.get(base); double convertRate = rates.get(convert); double usdRate = rates.get("USD"); double result = 0; if (baseRate <= usdRate) { double usd = value / baseRate; result = usd * convertRate; } else { double usd = value * baseRate; result = usd * convertRate; } return result; } }