generated from clean-code-workshop/sigrid-training-2024
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
4c582fc
commit 6c62329
Showing
1 changed file
with
16 additions
and
9 deletions.
There are no files selected for viewing
25 changes: 16 additions & 9 deletions
25
training-assignments/src/java/eu/sig/training/ch04-duplication/bankaccounts/Accounts.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 |
---|---|---|
@@ -1,20 +1,27 @@ | ||
package eu.sig.training.ch04; | ||
package eu.sig.training.ch04.v4; | ||
|
||
public class Accounts { | ||
@SuppressWarnings("unused") | ||
public static CheckingAccount findAcctByNumber(String number) { | ||
return new CheckingAccount(); | ||
public static SavingsAccount findAcctByNumber(String number) { | ||
return new SavingsAccount(); | ||
import eu.sig.training.ch04.BusinessException; | ||
import eu.sig.training.ch04.Money; | ||
import eu.sig.training.ch04.v3.CheckingAccount; | ||
|
||
// tag::Account[] | ||
public class Account { | ||
public Transfer makeTransfer(String counterAccount, Money amount) | ||
throws BusinessException { | ||
if (isValid(counterAccount)) { | ||
CheckingAccount acct = Accounts.findAcctByNumber(counterAccount); | ||
return new Transfer(this, acct, amount); | ||
} else { | ||
throw new BusinessException("Invalid account number!"); | ||
} | ||
} | ||
|
||
// tag::isValid[] | ||
public static boolean isValid(String number) { | ||
int sum = 0; | ||
for (int i = 0; i < number.length(); i++) { | ||
sum = sum + (9 - i) * Character.getNumericValue(number.charAt(i)); | ||
} | ||
return sum % 11 == 0; | ||
} | ||
// end::isValid[] | ||
} | ||
// end::Account[] |