/*
* ExchangeRateCalculator.java
*
* Created on: 27-Feb-2010
*
*/
package netukar.exchange;
/**
*
* @author radovan
*/
public class ExchangeRateCalculator {
private int precision;
/**
* Creates a new instance of ExchangeRateCalculator.
*/
public ExchangeRateCalculator() {
precision = 3;
}
public double calculate(double amount, Currency in, Currency out) {
double rate = ExchangeRateTable.getInstance().getExchangeRate(in, out);
return amount * rate;
}
/**
* @throw IllegalArgumentException
* if either parameter from
or to
cannot
* be mapped to any Currency
enumeration type
*/
public double calculate(double amount, String from, String to) {
Currency in = Currency.valueOf(from);
Currency out = Currency.valueOf(to);
return calculate(amount, in, out);
}
public Exchange calculate(Exchange exchange, Currency out) {
double amount = calculate(exchange.getAmount(), exchange.getCurrency(), out);
Exchange result = new Exchange();
result.setCurrency(out);
result.setAmount(amount);
return result;
}
}