-
Notifications
You must be signed in to change notification settings - Fork 20
BankAccount Wave 3 plus optionals #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: mmr/master
Are you sure you want to change the base?
Changes from all commits
b79bdfe
7365ecc
c7c9139
97a41a2
9a275eb
50ea4b5
f7d8be0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| module Bank | ||
|
|
||
| require 'csv' | ||
|
|
||
| class Account | ||
|
|
||
| # @@min_balance = 0 | ||
|
|
||
| attr_accessor :balance, :account_id, :owner | ||
|
|
||
| def initialize(account_id, balance, datetime_open, owner = nil) | ||
| @account_id = account_id | ||
| @balance = balance | ||
| @withdrawal_fee = 0 | ||
| @min_balance = 0 | ||
| if balance < @min_balance | ||
| raise ArgumentError.new("Cannot start an account with a negative balance.") | ||
| end | ||
| @datetime_open = DateTime.strptime(datetime_open, "%Y-%m-%d %H:%M:%S %z") | ||
| @owner = owner | ||
| end | ||
|
|
||
| def self.all | ||
| accounts_csv = CSV.read("./support/accounts.csv") | ||
| accounts_instances = [] | ||
| accounts_csv.each do |row| | ||
| accounts_instances.push(Account.new(row[0], row[1].to_i, row[2])) | ||
| end | ||
| return accounts_instances | ||
| end | ||
|
|
||
| def self.find(id) | ||
| self.all.find do |line| | ||
| line.account_id.to_i == id | ||
| end | ||
| # new_account = Account.new(matched_id[0], matched_id[1], matched_id[2]) | ||
| # puts new_account | ||
| end | ||
|
|
||
| def self.everything | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice job putting everything together! |
||
| account_owners_csv = CSV.read("./support/account_owners.csv") | ||
| everything_array = [] | ||
| account_owners_csv.each do |line| | ||
| each_account = self.find(line[0].to_i) | ||
| each_owner = Bank::Owner.find(line[1].to_i) | ||
| each_account.assign_owner(each_owner) | ||
| everything_array.push(each_account) | ||
| end | ||
| return everything_array | ||
| end | ||
|
|
||
| def withdraw(withdraw_amount) | ||
| # returns updated balance | ||
| if withdraw_amount > (@balance + @withdrawal_fee) | ||
| puts "Not enough money in account" | ||
| puts "The current balance is only: #{@balance}" | ||
| else | ||
| @balance = (@balance - withdraw_amount - @withdrawal_fee) | ||
| puts "Updated balance is: #{@balance}" | ||
| end | ||
| end | ||
|
|
||
| def deposit(deposit_amount) | ||
| # returns updated balance | ||
| @balance += deposit_amount | ||
| puts "Updated balance is: #{@balance}" | ||
| end | ||
|
|
||
| def add_interest(rate) | ||
| interest = @balance * rate/100 | ||
| puts "The interest earned on the account is: $#{interest.to_i}" | ||
| @balance = @balance + interest | ||
| puts "The new balance is: $#{@balance.to_i}" | ||
| end | ||
|
|
||
|
|
||
| # def assign_owner(owner_hash) | ||
| # @owner = owner | ||
| # # puts "The owner of this account is #{@owner.first_name} #{@owner.last_name}." | ||
| # end | ||
| end | ||
|
|
||
| class Owner | ||
|
|
||
| attr_reader :owner_id, :first_name, :last_name, :street, :city, :state, :zip | ||
|
|
||
| def initialize(owner_hash) | ||
| @owner_id = owner_hash[:owner_id] | ||
| @first_name = owner_hash[:first_name] | ||
| @last_name = owner_hash[:last_name] | ||
| @street = owner_hash[:street] | ||
| @city = owner_hash[:city] | ||
| @state = owner_hash[:state] | ||
| @zip = owner_hash[:zip] | ||
| end | ||
|
|
||
| def self.all | ||
| owners_csv = CSV.read("./support/owners.csv") | ||
| owners_array = [] | ||
| owners_csv.each do |row| | ||
| owner_hash = {:owner_id => row[0], :last_name => row[1], :first_name => row[2], :street => row[3], :city => row[4], :state => row[5]} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would split this out onto separate lines to make it more readable |
||
| owners_array.push Owner.new(owner_hash) | ||
| end | ||
| return owners_array | ||
| end | ||
|
|
||
| def self.find(id) | ||
| self.all.find do |line| | ||
| line.owner_id.to_i == id | ||
| end | ||
| end | ||
|
|
||
| # def self.everything | ||
| # account_owners_csv = CSV.read("./support/account_owners.csv") | ||
| # everything_array = [] | ||
| # account_owners_csv.each do |line| | ||
| # each_owner = self.find(line[1].to_i) | ||
| # each_account = Bank::Account.find(line[0].to_i) | ||
| # each_owner.account = each_account | ||
| # everything_array.push(each_owner) | ||
| # end | ||
| # return everything_array | ||
| # end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| require "./account.rb" | ||
| require "./savings_account.rb" | ||
| require "./checking_account.rb" | ||
| require "./moneymarket_account.rb" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| module Bank | ||
|
|
||
| require 'csv' | ||
|
|
||
| class CheckingAccount < Account | ||
|
|
||
| def initialize(account_id, balance, datetime_open, owner = nil) | ||
| super | ||
| @withdrawal_fee = 1 | ||
| @checks_used = 0 | ||
| end | ||
|
|
||
| def withdraw_using_check(amount) | ||
| if @checks_used >= 3 | ||
| @withdrawal_fee = 0 | ||
| end | ||
| if (@balance - amount - @withdrawal_fee) < -10 | ||
| puts "Unable to make this withdrawal" | ||
| else | ||
| @balance -= (amount + @withdrawal_fee) | ||
| puts @withdrawal_fee | ||
| puts "The new balance is: #{@balance}" | ||
| @checks_used += 1 | ||
| end | ||
| return @balance | ||
| end | ||
|
|
||
| def add_interest(rate) | ||
| return "Not a function of this account." | ||
| end | ||
|
|
||
| def reset_checks | ||
| @checks_used = 0 | ||
| @withdrawal_fee = 1 | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| module Bank | ||
|
|
||
| require 'csv' | ||
|
|
||
| class MoneyMarket < Account | ||
|
|
||
| # @@min_balance = 10000 | ||
|
|
||
| attr_accessor :transactions | ||
|
|
||
| def initialize(account_id, balance, datetime_open, owner = nil) | ||
| super | ||
| #max of 6 transactions (deposit or withdrawal) | ||
| #initial balance !< $10000 - will raise ArgumentError | ||
| @min_balance = 10000 | ||
| @transactions = 0 | ||
| @min_balance_fee = 100 | ||
| end | ||
|
|
||
| # def transactions() | ||
| # @transactions += 1 | ||
| # end | ||
|
|
||
| def withdraw(withdraw_amount) | ||
| if (@balance - withdraw_amount) < @min_balance && @transactions < 6 | ||
| @balance -= (@min_balance_fee) | ||
| puts "A $100 fee is imposed for going below $10000" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you have variables that store these variables, I would use the variables in this error message b/c if the values changed, then you wouldn't need to change this message |
||
| end | ||
| if @transactions >= 6 | ||
| puts "No more transactions left available this month." | ||
| else | ||
| @balance -= withdraw_amount | ||
| @transactions += 1 | ||
| end | ||
| end | ||
|
|
||
| def deposit(deposit_amount) | ||
| if @balance >= @@min_balance | ||
| if @transactions < 6 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You use this |
||
| super | ||
| @transactions += 1 | ||
| else | ||
| puts "No more transactions left available this month." | ||
| end | ||
| else | ||
| super | ||
| end | ||
| end | ||
|
|
||
| def reset_transactions | ||
| @transactions = 0 | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| module Bank | ||
|
|
||
| require 'csv' | ||
|
|
||
| class SavingsAccount < Account | ||
|
|
||
| # @@min_balance = 10 | ||
|
|
||
| def initialize(account_id, balance, datetime_open, owner = nil) | ||
| super | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! |
||
| @min_balance = 10 | ||
| @withdrawal_fee = 2 | ||
| end | ||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice use of the default attribute for the owner