diff --git a/oop/code/OopBankAccount.java b/oop/code/OopBankAccount.java new file mode 100644 index 0000000..b341e06 --- /dev/null +++ b/oop/code/OopBankAccount.java @@ -0,0 +1,23 @@ +public class OopBankAccount { + private Integer number; + private Integer balance; + + public OopBankAccount(Integer number, Integer balance) { + this.number = number; + this.balance = balance; + } + + void deposit(Integer amount) { + this.balance += amount; + } + + void withdraw(Integer amount) { + this.balance += amount; + } + + void transfer(OopBankAccount destination, Integer amount) { + this.withdraw(amount); + destination.deposit(amount); + } + +} diff --git a/oop/code/procedural_transfer.py b/oop/code/procedural_transfer.py new file mode 100644 index 0000000..55d97b7 --- /dev/null +++ b/oop/code/procedural_transfer.py @@ -0,0 +1,23 @@ + +accounts = [] + +def transfer(source: int, destination: int, amount: int) -> None: + + source_account = get_account(source) + update_account(source_account, -amount) + + destination_account = get_account(destination) + update_account(destination_account, amount) + +def get_account(number: int) -> dict: + return list(filter(lambda account: account['number'] == number, accounts))[0] + +def update_account(account: int, delta: int) -> None: + account['balance'] += delta + +if __name__ == '__main__': + accounts.append({'number': 1, 'balance': 100}) + accounts.append({'number': 2, 'balance': 200}) + + transfer(1, 2, 50) + print(accounts) \ No newline at end of file