2 回答

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超5個(gè)贊
這是一個(gè)小問題
如果您看到此功能,您將帳戶類型更改為'Savings' 或 'Checking'。
public void calculateNewBalance()
{
if (accountType.equals("S") || accountType.equals("s"))
{
accountType = "Savings";
calculateSavingsBalance();
} else if (accountType.equals("C") || accountType.equals("c"))
{
accountType = "Checking";
calculateCheckingBalance();
}
}
然而,您正在將 accountType 與'c' 或 's'進(jìn)行比較
public void isServiceCharge()
{
if(accountType.equals("s") || accountType.equals("S"))
{
double newBalance = currentBalance - 10.0;
JOptionPane.showMessageDialog(null, "Account Number: " + getAccountNumber() + "\nAccount Type: " + getAccountType() + "\nMinimum Balance: $" + getMinSavings()
+ "\nBalance Before Interest and Fees: $" + getCurrentBalance() + "\n\nNew Balance: $" + newBalance);
}
else if(accountType.equals("c") || accountType.equals("C"))
{
double newBalance = currentBalance - 25.0;
JOptionPane.showMessageDialog(null, "Account Number: " + getAccountNumber() + "\nAccount Type: " + getAccountType() + "\nMinimum Balance: $" + getMinSavings()
+ "\nBalance Before Interest and Fees: $" + getCurrentBalance() + "\n\nNew Balance: $" + newBalance);
}
}
這就是它沒有進(jìn)入任何一個(gè)塊的原因,因此,如果您將條件更改為以下語句
if(accountType.equals("Savings"))
else if(accountType.equals("Checking"))
它會(huì)按您的預(yù)期工作

TA貢獻(xiàn)1813條經(jīng)驗(yàn) 獲得超2個(gè)贊
你的代碼中實(shí)際發(fā)生了什么,
public void calculateNewBalance()
{
if (accountType.equals("S") || accountType.equals("s"))
{
accountType = "Savings";
calculateSavingsBalance();
} else if (accountType.equals("C") || accountType.equals("c"))
{
accountType = "Checking";
calculateCheckingBalance();
}
}
for s or S accountType = "Savings";
對(duì)于c 或 C accountType = "正在檢查";
但有趣的是在isServiceCharge()方法中
public void isServiceCharge()
{
if(accountType.equals("s") || accountType.equals("S"))
{
double newBalance = currentBalance - 10.0;
JOptionPane.showMessageDialog(null, "Account Number: " + getAccountNumber() + "\nAccount Type: " + getAccountType() + "\nMinimum Balance: $" + getMinSavings()
+ "\nBalance Before Interest and Fees: $" + getCurrentBalance() + "\n\nNew Balance: $" + newBalance);
}
else if(accountType.equals("c") || accountType.equals("C"))
{
double newBalance = currentBalance - 25.0;
JOptionPane.showMessageDialog(null, "Account Number: " + getAccountNumber() + "\nAccount Type: " + getAccountType() + "\nMinimum Balance: $" + getMinSavings()
+ "\nBalance Before Interest and Fees: $" + getCurrentBalance() + "\n\nNew Balance: $" + newBalance);
}
}
你檢查過
accountType.equals("s") || accountType.equals("S") //for savings
accountType.equals("C") || accountType.equals("c")// for checking
所以上述條件永遠(yuǎn)不會(huì)滿足。
所以解決辦法是:
public void isServiceCharge()
{
if(accountType.equals("Savings"))
{
double newBalance = currentBalance - 10.0;
JOptionPane.showMessageDialog(null, "Account Number: " + getAccountNumber() + "\nAccount Type: " + getAccountType() + "\nMinimum Balance: $" + getMinSavings()
+ "\nBalance Before Interest and Fees: $" + getCurrentBalance() + "\n\nNew Balance: $" + newBalance);
}
else if(accountType.equals("Checking"))
{
double newBalance = currentBalance - 25.0;
JOptionPane.showMessageDialog(null, "Account Number: " + getAccountNumber() + "\nAccount Type: " + getAccountType() + "\nMinimum Balance: $" + getMinSavings()
+ "\nBalance Before Interest and Fees: $" + getCurrentBalance() + "\n\nNew Balance: $" + newBalance);
}
}
添加回答
舉報(bào)