Skip to content

Commit

Permalink
aanpassing
Browse files Browse the repository at this point in the history
  • Loading branch information
daniquemont committed Jun 28, 2024
1 parent 02db874 commit b73ce29
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
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();
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("Account nummer klopt niet! 🐷 Probeer opnieuw");
}
}

// 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[]
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
package eu.sig.training.ch04.v4;
package eu.sig.training.ch04.v3;

import eu.sig.training.ch04.BusinessException;
import eu.sig.training.ch04.Money;
import eu.sig.training.ch04.v3.CheckingAccount;

// tag::Account[]
public class CheckingAccountccount {
// tag::CheckingAccount[]
public class CheckingAccount extends Account {
private int transferLimit = 10000000000000;

@Override
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("Account nummer klopt niet! 🐷 Probeer opnieuw");
}
}

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));
if (amount.greaterThan(this.transferLimit)) {
throw new BusinessException("Limit exceeded!");
}
return sum % 11 == 0;
return super.makeTransfer(counterAccount, amount);
}
}

0 comments on commit b73ce29

Please sign in to comment.