Java Reference
In-Depth Information
this.setName(name);
this.setAmount(new BigDecimal(amount));
} else {
throw new IllegalAccount();
}
}
 
@Override
public boolean isValidDeposit(String deposit) {
BigDecimal temp;
try {
temp = new BigDecimal(deposit);
} catch (Exception e) {
return false;
}
if (temp.compareTo(new BigDecimal.ZERO) > 0) {
if (temp.add(this.getAmount()).compareTo(minBalance) > 0) {
return true;
}
}
return false;
}
 
@Override
public void deposit(String deposit) throws IllegalDeposit {
if (isValidDeposit(deposit)) {
this.setAmount(this.getAmount().add(new BigDecimal(deposit)));
} else {
throw new IllegalDeposit();
}
}
 
@Override
public boolean isValidWithdrawal(String withdrawal) {
BigDecimal temp;
try {
temp = new BigDecimal(withdrawal);
} catch (Exception e) {
return false;
}
if (temp.compareTo(this.getAmount().add(minBalance)) < 0) {
return true;
}
return false;
}
 
@Override
public void withdraw(String withdrawal) throws IllegalWithdrawal {
if (isValidWithdrawal(withdrawal)) {
this.setAmount(this.getAmount()
.subtract(new BigDecimal(withdrawal)));
} else {
throw new IllegalWithdrawal();
}
}
 
Search WWH ::




Custom Search