我已经用jsf创建了一个货币转换器bean,我很难弄清楚如何修改 convert()
要设置的方法 targetCurrency
以外币和 targetAmount
以美元为单位。到目前为止,我掌握的情况如下:
@ManagedBean(name = "currMB")
@RequestScoped
public class Currency {
// Currency conversion factors as or 10/21/2019
private static final double CAN = 1.3128;
private static final double EUR = 0.8957;
private static final double JPN = 108.41;
private static final double UK = 0.7701;
public String name;
public String currencyType;
public double amount;
public Currency() { }
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCurrencyType() {
return currencyType;
}
public void setCurrencyType(String currencyType) {
this.currencyType = currencyType;
}
public double getAmount() {
return amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
public String convert() {
double targetAmount = 0.0;
String targetCurrency = null;
String result = "Cannot calculate conversion";
if (amount > 0.0) {
targetAmount = CAN;
targetAmount = EUR;
targetAmount = JPN;
targetAmount = UK;
}
if (targetCurrency != null && name != null) {
result = String.format("%.2f US Dollars is %.2f %s",
amount,targetAmount,targetCurrency);
}
return result;
}
}
谢谢你的帮助
暂无答案!
目前还没有任何答案,快来回答吧!