diff --git a/training-assignments/src/java/eu/sig/training/ch04-duplication/bankaccounts/CheckingAccount.java b/training-assignments/src/java/eu/sig/training/ch04-duplication/bankaccounts/CheckingAccount.java index 3e6fdbb..d341c92 100755 --- a/training-assignments/src/java/eu/sig/training/ch04-duplication/bankaccounts/CheckingAccount.java +++ b/training-assignments/src/java/eu/sig/training/ch04-duplication/bankaccounts/CheckingAccount.java @@ -1,41 +1,19 @@ -package eu.sig.training.ch04; +package eu.sig.training.ch04.v3; + +import eu.sig.training.ch04.BusinessException; +import eu.sig.training.ch04.Money; // tag::CheckingAccount[] -public class CheckingAccount { - private static final float INTEREST_PERCENTAGE = 0.01f; - private Money balance = new Money(); +public class CheckingAccount extends Account { private int transferLimit = 100; + @Override public Transfer makeTransfer(String counterAccount, Money amount) throws BusinessException { - // 1. Check withdrawal limit: if (amount.greaterThan(this.transferLimit)) { throw new BusinessException("Limit exceeded!"); } - // 2. Assuming result is 9-digit bank account number, validate 11-test: - int sum = 0; - for (int i = 0; i < counterAccount.length(); i++) { - char character = counterAccount.charAt(i); - int characterValue = Character.getNumericValue(character); - sum = sum + (9 - i) * characterValue; - } - if (sum % 11 == 0) { - // 3. Look up counter account and make transfer object: - CheckingAccount acct = Accounts.findAcctByNumber(counterAccount); - Transfer result = new Transfer(this, acct, amount); - return result; - } 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); - } + return super.makeTransfer(counterAccount, amount); } } // end::CheckingAccount[]