exchangerate.java
来自「JAVA Servlet2.3外文书籍源码」· Java 代码 · 共 37 行
JAVA
37 行
import java.util.Hashtable;
public class ExchangeRate {
private Hashtable rate_table;
public ExchangeRate() {
rate_table = new Hashtable(6);
rate_table.put( "CA", new Double( 1.562600)); //Canada
rate_table.put( "EU", new Double( 1.090394)); //Euro
rate_table.put( "JP", new Double(120.435000)); //Japan
rate_table.put( "MX", new Double( 9.589000)); //Mexico
rate_table.put( "UK", new Double( 0.676133)); //United Kingdom
rate_table.put( "US", new Double( 1.000000)); //United States
}
public double getExchangeRate(String country_code) {
Object obj = rate_table.get(country_code);
double rval = 0;
if (obj != null) {
rval = ((Double)obj).doubleValue();
}
return rval;
}
public double getExchangeRate(String country1, String country2){
double rval;
double currency1_per_usdollar = getExchangeRate( country1 );
double currency2_per_usdollar = getExchangeRate( country2 );
if( currency2_per_usdollar > 0.0 )
rval = currency1_per_usdollar/currency2_per_usdollar;
else
rval = 0.0;
return rval;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?