2 回答
TA贡献1811条经验 获得超5个赞
这是一个小问题
如果您看到此功能,您将帐户类型更改为'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'进行比较
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);
}
}
这就是它没有进入任何一个块的原因,因此,如果您将条件更改为以下语句
if(accountType.equals("Savings"))
else if(accountType.equals("Checking"))
它会按您的预期工作
TA贡献1813条经验 获得超2个赞
你的代码中实际发生了什么,
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";
对于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
所以上述条件永远不会满足。
所以解决办法是:
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);
}
}
添加回答
举报