From 2f288d8e9ba60cbfb17bbe6691740bb0202d46c4 Mon Sep 17 00:00:00 2001 From: Tammy Date: Thu, 8 Oct 2015 09:20:33 -0700 Subject: [PATCH 01/17] Made some changes --- bank.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bank.rb b/bank.rb index 39c01d35..b72cb53a 100644 --- a/bank.rb +++ b/bank.rb @@ -152,8 +152,8 @@ def self.owner_account sample = CSV.read("./support/account_owners.csv") owner_accounts_array =[] sample.each do |row| - account = Bank::Account.find(row[0]) - owner = self.find(row[1]) + account = Bank::Account.find(row[0].to_i) + owner = Bank::Owner.find(row[1].to_i) if account == nil break else From b79bdfe503a4328712f3ff1f93473a1f8a762833 Mon Sep 17 00:00:00 2001 From: Kari Bancroft Date: Thu, 8 Oct 2015 11:13:05 -0700 Subject: [PATCH 02/17] Add wave 3 --- README.md | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 25fd4d2a..b6e5c7b2 100644 --- a/README.md +++ b/README.md @@ -73,24 +73,23 @@ Create an `Account` class which should have the following functionality: **Account ID** - (Fixnum) a unique identifier corresponding to an account **Owner ID** - (Fixnum) a unique identifier corresponding to an owner - From 6ad1eef98eddee80c549575902395b0a7a2e2f37 Mon Sep 17 00:00:00 2001 From: Tammy Date: Thu, 8 Oct 2015 14:05:15 -0700 Subject: [PATCH 03/17] Start working --- saving_account.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 saving_account.rb diff --git a/saving_account.rb b/saving_account.rb new file mode 100644 index 00000000..6db5ac9b --- /dev/null +++ b/saving_account.rb @@ -0,0 +1,24 @@ +require "./bank.rb" + +class SavingsAccount < Account + + def initialize (id, balance, date) + super (id, initial_balance, date) + end + + def initial_balance + puts "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$".center(70) + puts + puts "$$$$$$$ Welcome to Tammy's Bank! $$$$$$$".center(70) + puts "How much $$$ would you like to deposit to your new account ?".center(70) + puts + puts "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$".center(70) + money = gets.chomp.to_i + if money < 10 + raise ArgumentError.new("You can't deposit negativ amount of money") + money = 0 + elsif money == 0 + puts "You have 30 days to deposit at least $10" + end + return money + end From b2cdbb76a3351f332a37ee08d01a3657d77df2e1 Mon Sep 17 00:00:00 2001 From: Tammy Date: Thu, 8 Oct 2015 15:10:46 -0700 Subject: [PATCH 04/17] Checking --- Owner.rb | 74 ++++++++++++++++++++++++++++++++++++++++++ lib/ChackingAccount.rb | 27 +++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 Owner.rb create mode 100644 lib/ChackingAccount.rb diff --git a/Owner.rb b/Owner.rb new file mode 100644 index 00000000..a38b4fcd --- /dev/null +++ b/Owner.rb @@ -0,0 +1,74 @@ +require "./bank.rb" +require "csv" +module Bank + + class Owner + + attr_accessor :id, :last_name, :first_name, :address, :city, :state + + def initialize (info_hash) + @id = info_hash [:id] + @last_name = info_hash [:last_name] + @first_name = info_hash [:first_name] + @address = info_hash [:address] + @city = info_hash [:city] + @state = info_hash [:state] + end + + def self.create_owner (person_array) + person_id = person_array[0].to_i + person_last_name = person_array[1] + person_first_name = person_array[2] + person_address = person_array[3] + person_city = person_array[4] + person_state = person_array[5] + owner = {id: person_id, + last_name: person_last_name, + first_name: person_first_name, + address: person_address, + city: person_city, + state: person_state + } + return Bank::Owner.new(owner) + end + + def self.all + sample = CSV.read("./support/owners.csv") + owners = [] + sample.each do |row| + owner = create_owner(row) + owners.push(owner) + end + return owners + end + + def self.find(id) + sample = CSV.read("./support/owners.csv") + sample.each do |row| + if row[0] == id + return create_owner(row) + end + end + end + + + ## Why isn't this working?? + + def self.owner_account + sample = CSV.read("./support/account_owners.csv") + owner_accounts_array =[] + sample.each do |row| + account = Bank::Account.find(row[0].to_i) + owner = Bank::Owner.find(row[1].to_i) + if account == nil + break + else + account.set_owner(owner) + owner_accounts_array.push(account) + end + return owner_accounts_array + end + end + + end +end diff --git a/lib/ChackingAccount.rb b/lib/ChackingAccount.rb new file mode 100644 index 00000000..b9bd8f80 --- /dev/null +++ b/lib/ChackingAccount.rb @@ -0,0 +1,27 @@ +module Bank + class CheckingAccount < Account + + + def withdraw (amount) + super (amount, 1) + end + + + # if amount + FEE > @balance + # puts "You have $#{@balance} in your account. Wirg 4! fee" + # puts "The maximun amount you can draw is #{@balance + 1} pennies" + # else + # puts "There is a $1 fee for each withdraw. Would you like to continue?" + # answer = gets.chomp.downcase + # if answer == y || answer == yes + # puts "You had $#{@balance/100}" + # @balance = @balance - amount - FEE + # puts "The update account balance is $#{@balance/100}" + # else + # puts "Ok, Bye!" + # end + # end + # return @balance + # end +end +end From 863a0dfce57d49efdcc75cf92cb3a5dbab8102f9 Mon Sep 17 00:00:00 2001 From: Tammy Date: Thu, 8 Oct 2015 15:11:13 -0700 Subject: [PATCH 05/17] working --- lib/saving_account.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 lib/saving_account.rb diff --git a/lib/saving_account.rb b/lib/saving_account.rb new file mode 100644 index 00000000..88cae446 --- /dev/null +++ b/lib/saving_account.rb @@ -0,0 +1,25 @@ +module Bank +class SavingsAccount < Account + + def initialize (id, balance, date) + super (id, initial_balance, date) + end + + def initial_balance + super (1) + end + + + def withdraw (amount) + super (amount, 2, 10) + end + + def dd_interest(rate) + interest = @balance * rate + @balance = @balance + interest + return interest + end + + + +end From 2c5d9e6a4dd2137000cc5b7902c0ce0a82b4e412 Mon Sep 17 00:00:00 2001 From: Tammy Date: Thu, 8 Oct 2015 15:11:41 -0700 Subject: [PATCH 06/17] changes --- lib/account.rb | 195 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 lib/account.rb diff --git a/lib/account.rb b/lib/account.rb new file mode 100644 index 00000000..6a47bb10 --- /dev/null +++ b/lib/account.rb @@ -0,0 +1,195 @@ + +module Bank + + class Account + @@count_accounts = 0 + + attr_accessor :id, :balance, :date, :owner + + def initialize (id, balance, date) + @balance = initial_balance + @id = id + @date = date + @@count_accounts += 1 + @owner = nil + #@owner = owner + end + + def set_owner (owner) + @owner = owner + end + + #get a row from index and return a new account + def self.create_account (person_array) + account_id = person_array[0].to_i + account_balance = person_array[1].to_i + account_date = person_array[2] + return Bank::Account.new(account_id, account_balance, account_date) + end + + #read the CSV file and row by row use the "creat account" method to create accounts and + #push it to an array - and return it + def self.all + sample = CSV.read("./support/accounts.csv") + accounts = [] + sample.each do |row| + account = create_account(row) + accounts.push(account) + end + return accounts + end + + def self.find(id) + sample = CSV.read("./support/accounts.csv") + sample.find do |row| + if row[0].to_i == id + return create_account(row) + end + end + end + + end + + + + def initial_balance + puts "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$".center(70) + puts + puts "$$$$$$$ Welcome to Tammy's Bank! $$$$$$$".center(70) + puts "How much $$$ would you like to deposit to your new account ?".center(70) + puts + puts "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$".center(70) + money = gets.chomp.to_i + if money < 0 + raise ArgumentError.new("You can't deposit negativ amount of money") + money = 0 + elsif money == 0 + puts "You have 30 days to deposit at least $5" + end + return money + end + + + def withdraw (amount, fee = 0, min_balance = 0) + if amount > (@balance + fee + min_balance) #since there is a minimum of $10 balance + $2 fee + puts " Your current balance is $#{@balance}." + puts "You can't go below of #{min_balance} in your account. Pay attention for $#{fee} fee" + return @balance + else + puts "There is a $#{fee} fee for each withdraw. Would you like to continue?" + answer = gets.chomp.downcase + if answer == y || answer == yes + puts "You had $#{@balance/100}" + @balance = @balance - amount - fee + puts "Your update account balance is $#{@balance/100}" + end + end + end + end + end +# +# def deposit (amount) +# if amount < 0 +# puts "If you want to withdraw, that's a different method :)" +# else +# @balance = @balance + amount +# puts "After you deposited $#{amount/100}" +# puts "The update account balance is $#{@balance/100}" +# end +# end +# +# def print_balance +# puts "Your current balance is $#{@balance}" +# end +# +# end +# end +# # +# # +# class Owner +# +# attr_accessor :id, :last_name, :first_name, :address, :city, :state +# +# def initialize (info_hash) +# @id = info_hash [:id] +# @last_name = info_hash [:last_name] +# @first_name = info_hash [:first_name] +# @address = info_hash [:address] +# @city = info_hash [:city] +# @state = info_hash [:state] +# end +# +# def self.create_owner (person_array) +# person_id = person_array[0].to_i +# person_last_name = person_array[1] +# person_first_name = person_array[2] +# person_address = person_array[3] +# person_city = person_array[4] +# person_state = person_array[5] +# owner = {id: person_id, +# last_name: person_last_name, +# first_name: person_first_name, +# address: person_address, +# city: person_city, +# state: person_state +# } +# return Bank::Owner.new(owner) +# end +# +# def self.all +# sample = CSV.read("./support/owners.csv") +# owners = [] +# sample.each do |row| +# owner = create_owner(row) +# owners.push(owner) +# end +# return owners +# end +# +# def self.find(id) +# sample = CSV.read("./support/owners.csv") +# sample.each do |row| +# if row[0] == id +# return create_owner(row) +# end +# end +# end +# +# +# ## Why isn't this working?? +# +# def self.owner_account +# sample = CSV.read("./support/account_owners.csv") +# owner_accounts_array =[] +# sample.each do |row| +# account = Bank::Account.find(row[0].to_i) +# owner = Bank::Owner.find(row[1].to_i) +# if account == nil +# break +# else +# account.set_owner(owner) +# owner_accounts_array.push(account) +# end +# end +# return owner_accounts_array +# end +# end +# end +# +# +# +# +# +# # +# # +# # nemo_hash = { +# # name: "Nemo", +# # address: "Seattle", +# # job: "Student", +# # id: 1283 +# # } +# # +# # nemo = Bank::Owner.new(nemo_hash) +# # +# # end +# # end From 2ead4c49c70880fcb352b95d0cc9f35f6d7eac2b Mon Sep 17 00:00:00 2001 From: Tammy Date: Thu, 8 Oct 2015 15:20:32 -0700 Subject: [PATCH 07/17] made changes --- lib/account.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 6a47bb10..138f8a01 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -52,7 +52,7 @@ def self.find(id) - def initial_balance + def initial_balance (min_balance = 0) puts "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$".center(70) puts puts "$$$$$$$ Welcome to Tammy's Bank! $$$$$$$".center(70) @@ -63,8 +63,8 @@ def initial_balance if money < 0 raise ArgumentError.new("You can't deposit negativ amount of money") money = 0 - elsif money == 0 - puts "You have 30 days to deposit at least $5" + elsif money < min_balance + raise ArgumentError.new("You can't deposit less then $#{min_balance}") end return money end From d3d3f741622ad82c00b3d83af5b540a18e2f6393 Mon Sep 17 00:00:00 2001 From: Tammy Date: Thu, 8 Oct 2015 16:15:37 -0700 Subject: [PATCH 08/17] yay --- lib/bank.rb | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 lib/bank.rb diff --git a/lib/bank.rb b/lib/bank.rb new file mode 100644 index 00000000..e2fd0ac8 --- /dev/null +++ b/lib/bank.rb @@ -0,0 +1,3 @@ +require "./saving_account.rb" +require "./chackingaccount.rb" +require "./account.rb" From b84d1c7b30f38fdc5ea5f7804c815d437b5f9c10 Mon Sep 17 00:00:00 2001 From: Tammy Date: Thu, 8 Oct 2015 16:16:42 -0700 Subject: [PATCH 09/17] yay --- lib/saving_account.rb | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/lib/saving_account.rb b/lib/saving_account.rb index 88cae446..9ed7cf12 100644 --- a/lib/saving_account.rb +++ b/lib/saving_account.rb @@ -1,25 +1,27 @@ module Bank -class SavingsAccount < Account + require "./account.rb" + class SavingsAccount < Account - def initialize (id, balance, date) - super (id, initial_balance, date) - end - def initial_balance - super (1) - end + def initialize (id, balance, date) + super + end + def initial_balance + super(1000) + end - def withdraw (amount) - super (amount, 2, 10) - end - def dd_interest(rate) - interest = @balance * rate - @balance = @balance + interest - return interest - end + def withdraw (amount) + super(amount, 200, 1000) #in cents + end + def add_interest(rate) + interest = @balance * rate + @balance = @balance + interest + return interest + end + end end From 6ed3a38dd9f4dd96f0e6a0629ad33e8f00d04f00 Mon Sep 17 00:00:00 2001 From: Tammy Date: Fri, 9 Oct 2015 14:40:24 -0700 Subject: [PATCH 10/17] looks good --- lib/MoneyMarketAccount.rb | 70 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 lib/MoneyMarketAccount.rb diff --git a/lib/MoneyMarketAccount.rb b/lib/MoneyMarketAccount.rb new file mode 100644 index 00000000..cfaa406e --- /dev/null +++ b/lib/MoneyMarketAccount.rb @@ -0,0 +1,70 @@ +module Bank + require "./account.rb" + + class MoneyMarketAccount < Account + + def initialize (id, date) + super + @num_transactions = 0 + end + + def initial_balance (1000000) + super + end + + def withdraw (amount, 100, 1000000) + if check_transactions && check_balance + super(amount, 100, 1000000) + if show_balance < 1000000 + puts "You can't do more transactions until the balance is decrease to $10,000" + end + @num_transactions +=1 + else + puts "You can't withdraw money. Think why" + end + end + + #check if the costumer want to depit monet to reach the minimum balance + def reach_min_balance (amount) + if (show_balance < 1000000) && (amount > (1000000 - show_balance)) + return true + else + return false + end + end + + + + def deposit (amount) + if check_transactions && check_balance ## check that the num of trasactions are less then 7 & the balance more then 10,000$ + super + @num_transactions += 1 + else + if reach_min_balance(amount) #if he want to deposit money to reach $10,000 - don't count transactions + super(amout) + end + end + + def check_transactions + if @num_transactions < 7 + return true + else + return false + end + end + + def check_balance + if show_balance < 1000000 + return false + else + return true + end + end + + + + + + + end +end From c41b9e316257e14f2dcc8a216455e1789e3ee9ae Mon Sep 17 00:00:00 2001 From: Tammy Date: Fri, 9 Oct 2015 14:44:03 -0700 Subject: [PATCH 11/17] some changes --- lib/account.rb | 160 +++++++++++-------------------------------------- 1 file changed, 34 insertions(+), 126 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 138f8a01..8a05fbc6 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -1,4 +1,3 @@ - module Bank class Account @@ -6,21 +5,20 @@ class Account attr_accessor :id, :balance, :date, :owner - def initialize (id, balance, date) + def initialize(id, date) @balance = initial_balance @id = id @date = date @@count_accounts += 1 @owner = nil - #@owner = owner end - def set_owner (owner) + def set_owner(owner) @owner = owner end #get a row from index and return a new account - def self.create_account (person_array) + def self.create_account(person_array) account_id = person_array[0].to_i account_balance = person_array[1].to_i account_date = person_array[2] @@ -48,7 +46,6 @@ def self.find(id) end end - end @@ -65,131 +62,42 @@ def initial_balance (min_balance = 0) money = 0 elsif money < min_balance raise ArgumentError.new("You can't deposit less then $#{min_balance}") + money = 0 end return money end + def show_balance + retuen @balance + end - def withdraw (amount, fee = 0, min_balance = 0) - if amount > (@balance + fee + min_balance) #since there is a minimum of $10 balance + $2 fee - puts " Your current balance is $#{@balance}." - puts "You can't go below of #{min_balance} in your account. Pay attention for $#{fee} fee" - return @balance - else - puts "There is a $#{fee} fee for each withdraw. Would you like to continue?" - answer = gets.chomp.downcase - if answer == y || answer == yes - puts "You had $#{@balance/100}" - @balance = @balance - amount - fee - puts "Your update account balance is $#{@balance/100}" + + def withdraw (amount, fee = 0, min_balance = 0) + if amount > (@balance + fee + min_balance) #since there is a minimum of $10 balance + $2 fee + puts " Your current balance is $#{@balance/100}." + puts "You can't go below of #{min_balance} in your account. Pay attention for $#{fee/100} fee" + return @balance + else + puts "There is a $#{fee/100} fee for this withdraw. Would you like to continue?" + answer = gets.chomp.downcase + if answer == "y" || answer == "yes" + puts "You had $#{@balance/100}" + @balance = @balance - amount - fee + puts "Your update account balance is $#{@balance/100}" + end end end + + def deposit (amount) + if amount < 0 + puts "If you want to withdraw, that's a different method :)" + else + @balance = @balance + amount + puts "After you deposited $#{amount/100}" + puts "The update account balance is $#{@balance/100}" + end + end + + end - end - end -# -# def deposit (amount) -# if amount < 0 -# puts "If you want to withdraw, that's a different method :)" -# else -# @balance = @balance + amount -# puts "After you deposited $#{amount/100}" -# puts "The update account balance is $#{@balance/100}" -# end -# end -# -# def print_balance -# puts "Your current balance is $#{@balance}" -# end -# -# end -# end -# # -# # -# class Owner -# -# attr_accessor :id, :last_name, :first_name, :address, :city, :state -# -# def initialize (info_hash) -# @id = info_hash [:id] -# @last_name = info_hash [:last_name] -# @first_name = info_hash [:first_name] -# @address = info_hash [:address] -# @city = info_hash [:city] -# @state = info_hash [:state] -# end -# -# def self.create_owner (person_array) -# person_id = person_array[0].to_i -# person_last_name = person_array[1] -# person_first_name = person_array[2] -# person_address = person_array[3] -# person_city = person_array[4] -# person_state = person_array[5] -# owner = {id: person_id, -# last_name: person_last_name, -# first_name: person_first_name, -# address: person_address, -# city: person_city, -# state: person_state -# } -# return Bank::Owner.new(owner) -# end -# -# def self.all -# sample = CSV.read("./support/owners.csv") -# owners = [] -# sample.each do |row| -# owner = create_owner(row) -# owners.push(owner) -# end -# return owners -# end -# -# def self.find(id) -# sample = CSV.read("./support/owners.csv") -# sample.each do |row| -# if row[0] == id -# return create_owner(row) -# end -# end -# end -# -# -# ## Why isn't this working?? -# -# def self.owner_account -# sample = CSV.read("./support/account_owners.csv") -# owner_accounts_array =[] -# sample.each do |row| -# account = Bank::Account.find(row[0].to_i) -# owner = Bank::Owner.find(row[1].to_i) -# if account == nil -# break -# else -# account.set_owner(owner) -# owner_accounts_array.push(account) -# end -# end -# return owner_accounts_array -# end -# end -# end -# -# -# -# -# -# # -# # -# # nemo_hash = { -# # name: "Nemo", -# # address: "Seattle", -# # job: "Student", -# # id: 1283 -# # } -# # -# # nemo = Bank::Owner.new(nemo_hash) -# # -# # end -# # end +end From f0116e918853752b5b6c4f98d045386dd027a900 Mon Sep 17 00:00:00 2001 From: Tammy Date: Fri, 9 Oct 2015 16:09:47 -0700 Subject: [PATCH 12/17] yay --- lib/account.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 8a05fbc6..847ac43f 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -49,7 +49,7 @@ def self.find(id) - def initial_balance (min_balance = 0) + def initial_balance(min_balance = 0) puts "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$".center(70) puts puts "$$$$$$$ Welcome to Tammy's Bank! $$$$$$$".center(70) @@ -60,14 +60,14 @@ def initial_balance (min_balance = 0) if money < 0 raise ArgumentError.new("You can't deposit negativ amount of money") money = 0 - elsif money < min_balance + elsif money < min_balance.to_i raise ArgumentError.new("You can't deposit less then $#{min_balance}") money = 0 end return money end - def show_balance + def show_balance retuen @balance end @@ -99,5 +99,13 @@ def deposit (amount) end + def add_interest(rate) + interest = @balance * rate + @balance = @balance + interest + return interest + end + + + end end From cd8aea4ac72ac7dbb2a7426c5d5fe82f0c7d3eb2 Mon Sep 17 00:00:00 2001 From: Tammy Date: Fri, 9 Oct 2015 16:10:09 -0700 Subject: [PATCH 13/17] yay --- lib/saving_account.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/saving_account.rb b/lib/saving_account.rb index 9ed7cf12..d56576fd 100644 --- a/lib/saving_account.rb +++ b/lib/saving_account.rb @@ -1,9 +1,9 @@ module Bank - require "./account.rb" + require "./account.rb" class SavingsAccount < Account - def initialize (id, balance, date) + def initialize(id, date) super end @@ -12,15 +12,13 @@ def initial_balance end - def withdraw (amount) + def withdraw(amount) super(amount, 200, 1000) #in cents end def add_interest(rate) - interest = @balance * rate - @balance = @balance + interest - return interest + super(rate) end end From 6eada02e24db110104a89887dc615cf5eb42b11f Mon Sep 17 00:00:00 2001 From: Tammy Date: Sun, 11 Oct 2015 21:27:29 -0700 Subject: [PATCH 14/17] Finish --- lib/bank.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/bank.rb b/lib/bank.rb index e2fd0ac8..afb88586 100644 --- a/lib/bank.rb +++ b/lib/bank.rb @@ -1,3 +1,28 @@ +module Bank require "./saving_account.rb" require "./chackingaccount.rb" require "./account.rb" +require "./MoneyMarketAccount.rb" +# +# d = Bank::CheckingAccount.new(100000, 11-12-15) +# +# d.withdraw(500) +# +# p = Bank::SavingsAccount.new(123, 11-12-12) +# +# p.withdraw(1000) + +# r = Bank::MoneyMarketAccount.new(12, 12-12-12) +# +# r.withdraw(1000) +# +# r.withdraw(500) +# +# 10.times do +# (r.withdraw(200)) +# end + + + + +end From acf1787d44605de6e2ee5c6acff7392035c5279b Mon Sep 17 00:00:00 2001 From: Tammy Date: Sun, 11 Oct 2015 21:28:59 -0700 Subject: [PATCH 15/17] finish --- lib/account.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 847ac43f..e31ebdea 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -61,17 +61,12 @@ def initial_balance(min_balance = 0) raise ArgumentError.new("You can't deposit negativ amount of money") money = 0 elsif money < min_balance.to_i - raise ArgumentError.new("You can't deposit less then $#{min_balance}") + raise ArgumentError.new("You can't deposit less then $#{min_balance/100}") money = 0 end return money end - def show_balance - retuen @balance - end - - def withdraw (amount, fee = 0, min_balance = 0) if amount > (@balance + fee + min_balance) #since there is a minimum of $10 balance + $2 fee puts " Your current balance is $#{@balance/100}." From c93c8a409da1708a64c60451de2965f4254b7dd2 Mon Sep 17 00:00:00 2001 From: Tammy Date: Sun, 11 Oct 2015 23:45:38 -0700 Subject: [PATCH 16/17] finish --- lib/ChackingAccount.rb | 44 +++++++++++++---------- lib/MoneyMarketAccount.rb | 62 +++++++++++++++++++++------------ lib/Owner.rb | 73 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+), 42 deletions(-) create mode 100644 lib/Owner.rb diff --git a/lib/ChackingAccount.rb b/lib/ChackingAccount.rb index b9bd8f80..4503f79f 100644 --- a/lib/ChackingAccount.rb +++ b/lib/ChackingAccount.rb @@ -1,27 +1,33 @@ module Bank + require "./account.rb" class CheckingAccount < Account + attr_accessor :num_checks - def withdraw (amount) - super (amount, 1) + def initialize(id, date) + super + @num_checks = 0 end + def withdraw(amount) + super(amount, 100, 0) + end - # if amount + FEE > @balance - # puts "You have $#{@balance} in your account. Wirg 4! fee" - # puts "The maximun amount you can draw is #{@balance + 1} pennies" - # else - # puts "There is a $1 fee for each withdraw. Would you like to continue?" - # answer = gets.chomp.downcase - # if answer == y || answer == yes - # puts "You had $#{@balance/100}" - # @balance = @balance - amount - FEE - # puts "The update account balance is $#{@balance/100}" - # else - # puts "Ok, Bye!" - # end - # end - # return @balance - # end -end + def withdraw_using_check(amount) + if @balace < (amount - 100) # $10 in cents + raise ArgumentError.new("The account can't go into overdraft up to -$10") + elsif @num_checks > 3 + puts "Since you used more then 3 checks this month- you'll be charged with $2 fee" + @balance = @balance - 200 - amount + @num_checks += 1 + else + @balance = @balance - amount + end + puts " Your current balance is $#{@balace/100}" + end + + def reset_checks + @num_checks = 0 + end + end end diff --git a/lib/MoneyMarketAccount.rb b/lib/MoneyMarketAccount.rb index cfaa406e..747ba4a3 100644 --- a/lib/MoneyMarketAccount.rb +++ b/lib/MoneyMarketAccount.rb @@ -3,45 +3,61 @@ module Bank class MoneyMarketAccount < Account - def initialize (id, date) + attr_accessor :num_transactions + + def initialize(id, date) super @num_transactions = 0 end - def initial_balance (1000000) - super + def initial_balance + super(1000000) end - def withdraw (amount, 100, 1000000) - if check_transactions && check_balance - super(amount, 100, 1000000) - if show_balance < 1000000 - puts "You can't do more transactions until the balance is decrease to $10,000" - end + def withdraw(amount) + if check_transactions && check_min_balance + puts "Your balance was $#{@balance/100}" + @balance -= amount @num_transactions +=1 + puts "after you withdrew $#{amount/100}, your currecnt balance is $#{@balance/100}" + if @balance < 1000000 + puts "You can't do more transactions until the balance will increase to $10,000" + puts "and you've been charged with $100 fee" + @balance -= 100 + end + else + if !check_transactions + puts "Sorry you can't withdraw money since you've reached 6 transactions this month" else - puts "You can't withdraw money. Think why" + puts "you have $#{@balance/100} only in your account. Please deposit at least $#{1000000 - @balance}" + puts "It won't count as one of youe monthly transactions" + end end end #check if the costumer want to depit monet to reach the minimum balance - def reach_min_balance (amount) - if (show_balance < 1000000) && (amount > (1000000 - show_balance)) + def reach_min_balance(amount) + if (@balance < 1000000) && (amount > (1000000 - @balance)) return true else return false end end + def add_interest(rate) + super(rate) + end + def reset_transactions + @num_transactions = 0 + end - def deposit (amount) - if check_transactions && check_balance ## check that the num of trasactions are less then 7 & the balance more then 10,000$ + def deposit(amount) + if check_transactions && check_min_balance ## check that the num of trasactions are less then 7 & the balance more then 10,000$ super @num_transactions += 1 - else - if reach_min_balance(amount) #if he want to deposit money to reach $10,000 - don't count transactions - super(amout) + elsif reach_min_balance(amount) #if he want to deposit money to reach $10,000 - don't count transactions + super(amount) end end @@ -53,8 +69,12 @@ def check_transactions end end - def check_balance - if show_balance < 1000000 + def show_balance + puts "Your current balance is $#{@balance/100}" + end + + def check_min_balance + if @balance < 1000000 return false else return true @@ -62,9 +82,5 @@ def check_balance end - - - - end end diff --git a/lib/Owner.rb b/lib/Owner.rb new file mode 100644 index 00000000..ef02196b --- /dev/null +++ b/lib/Owner.rb @@ -0,0 +1,73 @@ +module Bank + require "./account.rb" + + class Owner + + attr_accessor :id, :last_name, :first_name, :address, :city, :state + + def initialize (info_hash) + @id = info_hash [:id] + @last_name = info_hash [:last_name] + @first_name = info_hash [:first_name] + @address = info_hash [:address] + @city = info_hash [:city] + @state = info_hash [:state] + end + + def self.create_owner (person_array) + person_id = person_array[0].to_i + person_last_name = person_array[1] + person_first_name = person_array[2] + person_address = person_array[3] + person_city = person_array[4] + person_state = person_array[5] + owner = {id: person_id, + last_name: person_last_name, + first_name: person_first_name, + address: person_address, + city: person_city, + state: person_state + } + return Bank::Owner.new(owner) + end + + def self.all + sample = CSV.read("./support/owners.csv") + owners = [] + sample.each do |row| + owner = create_owner(row) + owners.push(owner) + end + return owners + end + + def self.find(id) + sample = CSV.read("./support/owners.csv") + sample.each do |row| + if row[0] == id + return create_owner(row) + end + end + end + + + ## Why isn't this working?? + + def self.owner_account + sample = CSV.read("./support/account_owners.csv") + owner_accounts_array =[] + sample.each do |row| + account = Bank::Account.find(row[0].to_i) + owner = Bank::Owner.find(row[1].to_i) + if account == nil + break + else + account.set_owner(owner) + owner_accounts_array.push(account) + end + return owner_accounts_array + end + end + + end +end From bd8a0e85e47b81ec038330560658c25b63eb0d80 Mon Sep 17 00:00:00 2001 From: Tammy Date: Mon, 12 Oct 2015 16:32:26 -0700 Subject: [PATCH 17/17] fixed some errors --- lib/MoneyMarketAccount.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/MoneyMarketAccount.rb b/lib/MoneyMarketAccount.rb index 747ba4a3..6ea4962e 100644 --- a/lib/MoneyMarketAccount.rb +++ b/lib/MoneyMarketAccount.rb @@ -53,11 +53,18 @@ def reset_transactions end def deposit(amount) - if check_transactions && check_min_balance ## check that the num of trasactions are less then 7 & the balance more then 10,000$ - super - @num_transactions += 1 - elsif reach_min_balance(amount) #if he want to deposit money to reach $10,000 - don't count transactions + if check_min_balance ## check the balance is greater than 10,000$ + if !check_transactions #check that the num of trasactions are less then 7 & + puts "You've reached 6 trasactions this months. You can't deposit money" + else + super(amount) + @num_transactions += 1 + end + elsif reach_min_balance(amount) #if there is less then 10,000 in the acoount- but the deposit is greater than the gap - + super(amount) #doesn't count as a trasaction. + else super(amount) + @num_transactions += 1 end end