Created
February 11, 2014 04:34
-
-
Save themoxman/8929303 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Transaction | |
| attr_reader :name, :description, :amount, :purchase_date | |
| def initialize(name, description, amount, purchase_date) | |
| @name = name | |
| @description = description | |
| @amount = amount | |
| @purchase_date = purchase_date | |
| end | |
| end | |
| class BankAccount | |
| attr_accessor :transactions, :balance | |
| attr_reader :owner, :account_number | |
| def initialize(owner, balance) | |
| @owner = owner | |
| @balance = Float(balance) | |
| @account_number = rand(10**9..10**10) | |
| @transactions = [] | |
| end | |
| def add_transaction(some_transaction) | |
| @transactions << some_transaction | |
| end | |
| def current_balance | |
| # @transactions.inject(@balance) { |sum, transaction| sum + transaction.amount } | |
| @transactions.each { |transaction| @balance += transaction.amount } | |
| @balance | |
| end | |
| def transaction_count | |
| @transactions.count | |
| end | |
| def avg_transaction_amount | |
| total = @transactions.inject(0) { |sum, transaction| sum + transaction.amount } | |
| total / @transactions.count | |
| end | |
| def largest_purchase | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment