Παράδειγμα: νομισματικές ισοτιμίες
import java.util.TreeMap;
public class FXConvert {
private static TreeMap<String, Double> fxRate = new TreeMap<String, Double>();
static double convert(String from, String to, double value) {
double euro = value / fxRate.get(from);
return euro * fxRate.get(to);
}
public static void main(String args[]) {
// Euro rates
fxRate.put("USD", 1.27);
fxRate.put("JPY", 126.0);
fxRate.put("GBP", 0.68);
fxRate.put("CHF", 1.57);
fxRate.put("CAD", 1.53);
fxRate.put("SEK", 9.03);
System.out.println("5 SEK = " + convert("SEK", "JPY", 5) + " JPY");
System.out.println("100 GBP = " + convert("GBP", "CHF", 100) + " CHF");
}
}