-
Couldn't load subscription status.
- Fork 38
Haby Randall Bank Accounts #30
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: master
Are you sure you want to change the base?
Changes from all commits
4c6f7db
c7f1bea
fc87609
ff71675
d7ba438
5803629
b28a680
a57d631
c9eca1b
e210de6
3651023
fbd9277
4a88a92
e6c979c
0881911
897a05e
c9db8c4
1671c8b
f9af0b6
5ddf712
44d888c
e6a8ccc
dea67d0
0c0d33f
6a90016
3a8e0e8
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,58 @@ | ||
| require 'csv' | ||
| module Bank | ||
|
|
||
|
|
||
| class Account | ||
|
|
||
| def self.all | ||
| account = [] | ||
| CSV.open("/Users/habsr/ada/projects/BankAccounts/support/accounts.csv", "r").each do |file| | ||
| id = Integer(file[0]) | ||
| balance = Integer(file[1]) | ||
| open_date = file[2] | ||
| new_account = Account.new(id, balance, open_date) | ||
| account << new_account | ||
| end | ||
| return account | ||
| end | ||
|
|
||
| def self.find(id) | ||
| Account.all.each do |account| | ||
| if account.id == id | ||
| return account | ||
| end | ||
| end | ||
| puts "That account Does Not Exist" | ||
| end | ||
|
|
||
| attr_reader :id, :balance | ||
| def initialize(id, balance, open_date = nil) | ||
| @id = id | ||
| @balance = balance | ||
| @open_date = open_date | ||
| if @balance < 0 | ||
| raise ArgumentError.new "The starting balance cannot be negative" | ||
| end | ||
| end | ||
|
|
||
| def withdraw(withdrawal_amount) | ||
| if withdrawal_amount > @balance | ||
| puts "Warning, the balance cannot be negative" | ||
| @balance = @balance | ||
| elsif withdrawal_amount < 0 | ||
| raise ArgumentError.new "You cannot withdraw a negative amount" | ||
| else | ||
| @balance -= withdrawal_amount | ||
| end | ||
| end | ||
|
|
||
| def deposit(deposit_amount) | ||
| #raise ArgumentError.new("amount must be >= 0") if amount < 0 | ||
| if deposit_amount < 0 | ||
| raise ArgumentError.new "The deposit must be greater than 0" | ||
| else | ||
| @balance += deposit_amount | ||
| end | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| require 'csv' | ||
| require_relative '../lib/account' | ||
|
|
||
| module Bank | ||
|
|
||
| class CheckingAccount < Account | ||
| attr_reader :id, :balance | ||
| def initialize(id, balance) | ||
| @id = id | ||
|
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. super would be swell here! |
||
| @balance = balance | ||
| @check_num = 3 | ||
|
|
||
| def withdraw(withdrawal_amount) | ||
|
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 don't see any testing for this method... |
||
| check_balance = @balance - (withdrawal_amount + 1) | ||
| if check_balance < 0 | ||
| puts "Warning, this will be below 0 , " + (@balance.to_s) | ||
| else | ||
| super + (-1) | ||
|
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. Same problem with |
||
| end | ||
| end | ||
|
|
||
| def withdraw_with_check(withdrawal_amount) | ||
| if withdrawal_amount < 0 | ||
| raise ArgumentError.new "You cannot withdraw a negative amount" | ||
| elsif (@balance - withdrawal_amount) <= -11 | ||
| puts "Warning, the balance cannot be negative " | ||
| return @balance | ||
| else | ||
| withdrawal_fee = 0 | ||
| @balance -= withdrawal_amount + withdrawal_fee | ||
| @check_num -= 1 | ||
| if @check_num < 0 | ||
| withdrawal_fee = 2 | ||
| @balance -= withdrawal_fee | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def reset_checks | ||
| if @check_num <= 0 | ||
| @check_num = 3 | ||
| end | ||
| end | ||
|
|
||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| module Bank | ||
| class Owner | ||
|
|
||
| def initialize(owner_hash) | ||
| @name = owner_hash[:name] | ||
| @address = owner_hash[:address] | ||
| @account_number = owner_hash[:account_number] | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| require 'csv' | ||
| require_relative '../lib/account' | ||
|
|
||
| module Bank | ||
|
|
||
| class SavingsAccount < Account | ||
| attr_reader :id, :balance, :interest | ||
|
|
||
| def initialize(id, balance) | ||
|
|
||
|
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 can probably use super to set the instance variables. |
||
| raise ArgumentError.new "Balance must be at least $10" unless balance >= 10 | ||
| @id = id | ||
| @balance = balance | ||
| end | ||
|
|
||
| def withdraw(withdrawal_amount) | ||
| temp_balance = @balance - (withdrawal_amount + 2) | ||
| if temp_balance < 10 | ||
| puts "Warning, this will make your balance below your mininum , the current balance is " + (@balance.to_s) | ||
| @balance | ||
| else | ||
| super + (-2) | ||
|
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 should probably be:
Let me know if this is confusing. |
||
| end | ||
| end | ||
|
|
||
| def add_interest(rate) | ||
| if rate < 0 | ||
| raise ArgumentError.new "The interest rate cannot be negative" | ||
| else | ||
| interest = @balance * (rate / 100).to_f | ||
| @balance += interest | ||
| return interest | ||
| end | ||
| 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.
To make it so it'll work no matter where you clone the repo this should be:
CSV.open("support/accounts.csv", "r").each do |file|