Skip to content

Commit

Permalink
Update Accounts.java
Browse files Browse the repository at this point in the history
  • Loading branch information
JitseGoutbeek authored Jun 28, 2024
1 parent 4c582fc commit 6c62329
Showing 1 changed file with 16 additions and 9 deletions.
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[]

0 comments on commit 6c62329

Please sign in to comment.