瀏覽代碼

bankaccounts

Seth 5 年之前
父節點
當前提交
b3a812a05f
共有 1 個檔案被更改,包括 5 行新增1 行删除
  1. 5
    1
      src/main/java/rocks/zipcode/quiz5/objectorientation/account/BankAccount.java

+ 5
- 1
src/main/java/rocks/zipcode/quiz5/objectorientation/account/BankAccount.java 查看文件

@@ -21,7 +21,11 @@ public class BankAccount extends Account implements Transactable{
21 21
 
22 22
 
23 23
     public void deposit(Double amountToIncreaseBy) {
24
-        balance += amountToIncreaseBy;
24
+        if(amountToIncreaseBy >= 0) {
25
+            balance += amountToIncreaseBy;
26
+        } else {
27
+            throw new IllegalArgumentException();
28
+        }
25 29
     }
26 30
 
27 31
     public void withdrawal(Double amountToDecreaseBy) {