generated from clean-code-workshop/sigrid-training-2024
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
...ng-assignments/src/java/eu/sig/training/ch04-duplication/bankaccounts/savingsAccount.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[] |