-
Notifications
You must be signed in to change notification settings - Fork 20
Wave 3 Updates #66
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: bmk/master
Are you sure you want to change the base?
Wave 3 Updates #66
Changes from all commits
b79bdfe
36f9617
b0427c5
7e95693
c160a37
ad5ef2a
46c1b03
96429fb
deff1ec
3f07bcc
51c398b
fee9e4d
d04c3f2
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,31 @@ | ||
| module Bank | ||
| class CheckingAccount < Account | ||
| def initialize(id, initial_balance, open_date, owner = nil) | ||
| super | ||
| @num_checks_used = 0 | ||
| end | ||
|
|
||
| def withdraw(amount) | ||
| transaction_fee = 100 | ||
| return super(amount + transaction_fee) | ||
| end | ||
|
|
||
| def withdraw_using_check(amount) | ||
| min_balance = -1000 | ||
| if @num_checks_used >= 3 | ||
| amount += 200 | ||
| end | ||
| if (@balance - amount < min_balance) | ||
| puts "Your balance cannot be below the minimum amount of $#{min_balance/100}. Transaction terminated." | ||
| else | ||
| @num_checks_used += 1 | ||
| @balance -= amount | ||
| end | ||
| return @balance | ||
| end | ||
|
|
||
| def reset_checks | ||
| @num_checks_used = 0 | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| module Bank | ||
| class MoneyMarketAccount < Account | ||
| attr_reader :num_transactions, :transaction_allowed | ||
| def initialize(id, initial_balance, open_date, owner = nil) | ||
| @id = id | ||
| @balance = initial_balance | ||
| @min_balance = 1000000 | ||
| @open_date = open_date | ||
| @owner = owner | ||
| @num_transactions = 0 | ||
| @max_transactions = 6 | ||
| @bal_above_min = true | ||
| check_balance | ||
| end | ||
|
|
||
| def withdraw(amount) | ||
| below_min_balance_fee = 10000 | ||
| if @num_transactions >= @max_transactions | ||
| puts "You cannot make more than #{@max_transactions} transactions in one month. Transaction terminated." | ||
| else #number of transactions is less than the allotted maximum | ||
| if @bal_above_min | ||
| if (@balance - amount < @min_balance) #withdrawing the amount will put the account below the minimum balance | ||
| amount += below_min_balance_fee | ||
| puts "Your account is locked until you reach the minimum balance of $#{@min_balance}." | ||
| @bal_above_min = false | ||
| end | ||
| @balance -= amount | ||
| @num_transactions += 1 | ||
| return @balance | ||
| else #balance is below the minimum balance | ||
| puts "You cannot make another transaction until your balance is increased to the minimum balance, $#{@min_balance}." | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def deposit(amount) | ||
| if !@bal_above_min | ||
|
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 a good use of the boolean to track whether or not the balance is within the acceptable range |
||
| if (amount + @balance >= @min_balance) #enough funds to bring balance above min balance, will deposit | ||
| super(amount) | ||
| @bal_above_min = true | ||
| else | ||
| puts "You cannot make another transaction until your balance is increased to the minimum balance, $#{@min_balance}." | ||
| end | ||
| else #balance is above the minimum balance | ||
| if @num_transactions >= @max_transactions | ||
| puts "You cannot make more than #{@max_transactions} transactions in one month. Transaction terminated." | ||
| else #number of transactions is less than the maximum allowed transactions | ||
| super(amount) | ||
| @num_transactions += 1 | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def reset_transactions | ||
| @num_transactions = 0 | ||
| end | ||
|
|
||
| def add_interest(rate) | ||
| interest = @balance * (rate.to_f/100) | ||
| balance += interest | ||
| return interest | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
|
|
||
| module Bank | ||
| class SavingsAccount < Account | ||
| def initialize(id, initial_balance, open_date, owner = nil) | ||
| @id = id | ||
| @balance = initial_balance | ||
| @min_balance = 1000 | ||
| @open_date = open_date | ||
| @owner = owner | ||
| check_balance | ||
| end | ||
|
|
||
| def withdraw(amount) | ||
| transaction_fee = 200 | ||
| return super(amount + transaction_fee) | ||
| end | ||
|
|
||
| def add_interest(rate) | ||
| interest = @balance * (rate.to_f/100) | ||
| balance += interest | ||
| return interest | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,13 +4,18 @@ module Bank | |
| class Account | ||
| attr_reader :balance, :owner, :id, :open_date | ||
| def initialize(id, initial_balance, open_date, owner = nil) | ||
| if(initial_balance < 0) | ||
| raise ArgumentError, "Your initial balance must be a positive value." | ||
| end | ||
| @balance = initial_balance | ||
| @id = id | ||
| @balance = initial_balance | ||
| @min_balance = 0 | ||
| @open_date = open_date | ||
| @owner = owner | ||
| check_balance | ||
| end | ||
|
|
||
| def check_balance | ||
| if @balance < @min_balance | ||
| raise ArgumentError, "Your initial balance must be at least $#{@min_balance/100}." | ||
| end | ||
| end | ||
|
|
||
| def self.all | ||
|
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 use the CSV file to pull out the one account match in your |
||
|
|
@@ -43,8 +48,8 @@ def self.get_ultimate_list | |
| end | ||
|
|
||
| def withdraw(amount) | ||
| if (@balance < amount) | ||
| puts "This will result in a negative account balance. Transaction terminated." | ||
| if (@balance - amount < @min_balance) | ||
| puts "Your balance cannot be below the minimum amount of $#{@min_balance/100}. Transaction terminated." | ||
|
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. It seems like you use the |
||
| else | ||
| @balance -= amount | ||
| end | ||
|
|
@@ -79,6 +84,9 @@ def self.find(id) | |
| owner = Owner.new(match[0].to_i, match[1], match[2], match[3], match[4], match[5]) | ||
| return owner | ||
| end | ||
|
|
||
| end | ||
| end | ||
|
|
||
| require "./SavingsAccount.rb" | ||
| require "./CheckingAccount.rb" | ||
| require "./MoneyMarketAccount.rb" | ||
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 - this code is outside of the
ifstatement blocks so it does not need to have additional indentation