Skip to content

Commit

Permalink
Create savingsAccount.java
Browse files Browse the repository at this point in the history
  • Loading branch information
3rats authored Jun 28, 2024
1 parent a4a0491 commit 600cbf6
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package eu.sig.training.ch04;

// tag::SavingsAccount[]
public class SavingsAccount {
CheckingAccount registeredCounterAccount;

public Transfer makeTransfer(String counterAccount, Money amount)
throws BusinessException {
// 1. Assuming result is 9-digit bank account number,
// validate with 11-test:
if (Accounts.isValid(counterAccount)) { // <1>
// 2. Look up counter account and make transfer object:
CheckingAccount acct = Accounts.findAcctByNumber(counterAccount);
Transfer result = new Transfer(this, acct, amount); // <2>
if (result.getCounterAccount().equals(this.registeredCounterAccount))
{
return result;
} else {
throw new BusinessException("Counter-account not registered!");
}
} else {
throw new BusinessException("Invalid account number!!");
}
}

public void addInterest() {
Money interest = balance.multiply(INTEREST_PERCENTAGE);
if (interest.greaterThan(0)) {
balance.add(interest);
} else {
balance.substract(interest);
}
}

}
// end::SavingsAccount[]

0 comments on commit 600cbf6

Please sign in to comment.