在setter中使用if / else语句

时间:2017-09-14 01:45:16

标签: constructor field setter getter modifier

在我的UML中它告诉我如果值为负

则不要让字段更新
public void setCurrentBalance(double currentBalance)
{
    if (currentBalance <= 0)
        this.currentBalance = currentBalance;
    else
        this.currentBalance = currentBalance;
}

如果构造函数如下所示,这看起来是否正确:

    setAccountNumber(accountNumber);
    setOwnerFirstName(ownerFirstName);
    setOwnerLastName(ownerLastName);
    setCurrentBalance(currentBalance);
    setMinimumBalanceRequired(minimumBalanceRequired);

0 个答案:

没有答案