public Transfer makeTransfer(string counterAccount, Money amount) { // 1. Assuming result is 9-digit bank account number, validate 11-test: int sum = 0; // <1> for (int i = 0; i < counterAccount.Length; i++) { sum = sum + (9 - i) * (int)Char.GetNumericValue( counterAccount[i]); } if (sum % 11 == 0) { // 2. Look up counter account and make transfer object: CheckingAccount acct = Accounts.FindAcctByNumber(counterAccount); Transfer result = new Transfer(this, acct, amount); // <2> // 3. Check whether withdrawal is to registered counter account: if (result.CounterAccount.Equals(this.RegisteredCounterAccount)) { return result; } else { throw new BusinessException("Counter-account not registered!"); } } else { throw new BusinessException("Invalid account number!!"); } }
public Transfer MakeTransfer(String counterAccount, Money amount) { // 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++) { sum = sum + (9 - i) * (int)Char.GetNumericValue( counterAccount[i]); } 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!"); } }