-
Notifications
You must be signed in to change notification settings - Fork 20
Cas/master #73
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: cas/master
Are you sure you want to change the base?
Cas/master #73
Changes from all commits
b79bdfe
d8645fd
146a345
fa116e5
01b8668
94c0b04
69fc0c9
5f8867a
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,40 @@ | ||
| require "./bank_account" | ||
| require "./savings_and_checking" | ||
|
|
||
| # m = Bank::MoneyMarketAccount.new(1212, 1200000, "06291990") | ||
| # 6.times do | ||
| # m.withdraw(5000) | ||
| # end | ||
| # | ||
| # m.withdraw(4000) | ||
| # | ||
| # m.deposit(1000) | ||
|
|
||
| # #SAVINGS ACCOUNT CHECKS | ||
| # s = Bank::SavingsAccount.new(1212, 2000, "06291990") | ||
| # 2.times do | ||
| # s.withdraw(200) | ||
| # end | ||
| # | ||
| # s.add_interest(0.25) | ||
|
|
||
| #CHECKING ACCOUNT CHECKS | ||
| # c = Bank::CheckingAccount.new(1212, 2000, "06291990") | ||
| # c.withdraw(1000) | ||
| # | ||
| # 4. times do | ||
| # c.withdraw_using_check(300) | ||
| # end | ||
| # | ||
| # c.withdraw_using_check(600) | ||
|
|
||
| #MONEYMARKETACCOUNT CHECKS | ||
| m = Bank::MoneyMarketAccount.new(1212, 1000000, "06291990") | ||
| m.withdraw(5000) | ||
| m.deposit(1000000) | ||
|
|
||
| 5.times do | ||
| m.deposit(100) | ||
| end | ||
|
|
||
| m.withdraw(5000) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,10 +5,10 @@ module Bank | |
|
|
||
| class Account | ||
| attr_accessor :balance, :id, :owner, :open_date | ||
| def initialize(id, balance, open_date, owner = nil) | ||
| def initialize(id, balance, open_date) | ||
| @balance = balance.to_i | ||
| @id = 7383092 | ||
| @owner = owner | ||
| @owner = nil | ||
| @open_date = open_date | ||
| if @balance < 0 | ||
| raise ArgumentError, "Accounts cannot be opened with negative money" | ||
|
|
@@ -18,7 +18,7 @@ def initialize(id, balance, open_date, owner = nil) | |
| def withdraw(withdraw_amount) | ||
| if @balance < withdraw_amount | ||
| puts "Insufficient funds: withdraw denied. Your balance is #{@balance}." | ||
| elsif @balance >= withdraw_amount | ||
| elsif | ||
| @balance = @balance.to_i - withdraw_amount.to_i | ||
| puts "Here is your cash monays. Your account balance is now #{@balance}" | ||
| end | ||
|
|
@@ -56,26 +56,37 @@ def self.find(id) | |
| end | ||
|
|
||
| def self.associate_everything | ||
| account_and_owner_csv = CSV.read("support/account_owners.csv") | ||
| everything_array = [] | ||
| account_and_owner_csv.each do |line| | ||
| CSV.foreach("support/account_owners.csv") do |line| | ||
| each_account = Bank::Account.find(line[0].to_i) | ||
| each_owner = Bank::Owner.find(line[1].to_i) | ||
| each_account.add_owner(each_owner) | ||
| each_account.owner = each_owner | ||
|
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 switched to setting the owner directly, do you still need the |
||
| everything_array.push(each_account) | ||
| end | ||
| return everything_array | ||
| end | ||
|
|
||
| def self.find_owner(id) | ||
| account_and_owner_csv = CSV.read("support/account_owners.csv") | ||
| owner_csv_array = CSV.read("support/owners.csv") | ||
| found_line = account_and_owner_csv.find do |line| | ||
| line[0].to_i == id | ||
| end | ||
| found_owner = owner_csv_array.find do |line| | ||
| line[0].to_i == found_line[1].to_i | ||
| end | ||
| return found_owner | ||
| end | ||
| end | ||
|
|
||
| class Owner | ||
| attr_reader :account, :owner_id, :last_name, :first_name, :address, :city, :state | ||
| def initialize(id, last_name, first_name, address, city, state) | ||
| @account = account | ||
| @first_name = first_name | ||
| @last_name = last_name | ||
| @address = address | ||
| @owner_id = owner_id | ||
| #@account = account | ||
|
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. Hmmm what happened with the owner that made you decide to comment the attributes out? |
||
| #@first_name = first_name | ||
| # @last_name = last_name | ||
| #@address = address | ||
| #@owner_id = owner_id | ||
| end | ||
|
|
||
| def who_da_owna | ||
|
|
@@ -85,10 +96,8 @@ def who_da_owna | |
| def self.all | ||
| owner_csv_array = CSV.read("support/owners.csv") | ||
| owner_array = [] | ||
| owner_csv_array.each do |line| | ||
| owner_array.push(Owner.new(line[0], line[1], line[2], line[3], line[4], line[5])) | ||
| end | ||
| return owner_array | ||
| owner_array = owner_csv_array.map{ |line| | ||
| Owner.new(line[0], line[1], line[2], line[3], line[4], line[5]) } | ||
| end | ||
|
|
||
| def self.find(id) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| module Bank | ||
| class SavingsAccount < Account | ||
| def initialize(id, balance, open_date) | ||
| super(id, balance, open_date) | ||
| if @balance < 1000 | ||
|
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. Similar comment re: extra indentation here |
||
| raise ArgumentError, "Accounts cannot be opened with less than $10. Please try again." | ||
| end | ||
| end | ||
|
|
||
| def withdraw(withdraw_amount) | ||
| transaction_fee = 200 | ||
| temp_balance = @balance - transaction_fee.to_i - withdraw_amount.to_i | ||
|
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 like the way you've used a local variable here to keep track of balance before you've decided to set it later |
||
| if temp_balance < 1000 | ||
| puts "You cannot have less than $10. This withdraw has been cancelled." | ||
| else | ||
| @balance = temp_balance | ||
| puts "You new balance is #{@balance}" | ||
| end | ||
| return @balance | ||
| end | ||
|
|
||
| def add_interest(rate) | ||
| interest_rate = rate.to_f | ||
| added_rate = @balance * (interest_rate/100.to_f) | ||
| @balance += added_rate | ||
| puts "Your balance is #{@balance}" | ||
| return added_rate | ||
| end | ||
| end | ||
|
|
||
| class CheckingAccount < Account | ||
|
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. This is good but i'd prefer if this class and the money market class were in separate files |
||
| def initialize(id, balance, open_date) | ||
| super(id, balance, open_date) | ||
| @check_count = 0 | ||
| end | ||
|
|
||
| def withdraw(withdraw_amount) | ||
| transaction_fee = 100 | ||
| temp_balance = @balance - transaction_fee.to_i - withdraw_amount.to_i | ||
| if temp_balance < 0 | ||
| puts "You cannot have less than $0. This withdraw has been cancelled." | ||
| else | ||
| @balance = temp_balance | ||
| puts "Your new balance is #{@balance} and you have used #{@check_count} checks this month." | ||
| end | ||
| return @balance | ||
| end | ||
|
|
||
| def withdraw_using_check(amount) | ||
| many_checks_fee = 200 | ||
| temp_balance = @balance - amount.to_i | ||
| if @check_count > 2 | ||
| temp_balance -= many_checks_fee | ||
| puts "You've already used your 3 free checks. This transaction will incur a penalty." | ||
| end | ||
| if temp_balance < -1000 | ||
| puts "OVERDRAFT: You cannot have less than -$10. Transaction cancelled" | ||
| else | ||
| @balance = temp_balance | ||
| @check_count += 1 | ||
| puts "Your new balance is #{@balance} and you have used #{@check_count}checks this month." | ||
| end | ||
| return @balance | ||
| end | ||
|
|
||
| def reset_checks | ||
| @check_count = 0 | ||
| end | ||
| end | ||
|
|
||
| class MoneyMarketAccount < Account | ||
| def initialize(id, balance, open_date) | ||
| super(id, balance, open_date) | ||
| @transaction_count = 0 | ||
| if @balance < 1000000 | ||
| raise ArgumentError, "Accounts cannot be opened with less than $10000. Please try again." | ||
| end | ||
| end | ||
|
|
||
| def withdraw(withdraw_amount) | ||
| overdraft_fee = 10000 | ||
| if @balance < 1000000 | ||
| puts "Your account is frozen due to low funds. Deposit more to continue." | ||
| return @balance | ||
| end | ||
| if @transaction_count > 5 | ||
| puts "You have used all your transactions this month." | ||
| return @balance | ||
| end | ||
| @balance = @balance - withdraw_amount | ||
| if @balance < 1000000 | ||
|
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 numeric 1000000 value a lot so this would be a great place to use a constant instead of using the same numeric value in multiple places |
||
| @balance -= overdraft_fee | ||
| puts "OVERDRAFT. Your account can not have less than $10,000. A fee of $#{overdraft_fee/100} has been imposed. Deposit more money before withdrawing again." | ||
| end | ||
| @transaction_count += 1 | ||
| puts "#{@transaction_count} is the count and $#{@balance/100} dollars is your balance" | ||
| return @balance | ||
| end | ||
|
|
||
| def deposit(deposit_amount) | ||
| if @balance < 1000000 | ||
| @balance += deposit_amount | ||
| elsif @transaction_count >5 | ||
| puts "You have used all your transactions this month." | ||
| return @balance | ||
| else | ||
| @balance += deposit_amount | ||
| @transaction_count += 1 | ||
| end | ||
| puts "#{@transaction_count} is the count and $#{@balance/100} dollars is the balance" | ||
| return @balance | ||
| end | ||
|
|
||
| def add_interest(rate) | ||
| interest_rate = rate.to_f | ||
| added_rate = @balance * (interest_rate/100.to_f) | ||
| @balance += added_rate | ||
| return added_rate | ||
| end | ||
|
|
||
| def reset_transactions | ||
| transaction_count = 0 | ||
| puts "#{@transaction_count} is the count and #{@balance/100} is the balance" | ||
| 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.
Watch your indentation here - you'll want to have an additional indent within the
elsifblock