Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
6 changes: 2 additions & 4 deletions Bank-Account.rb → Bank.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ def initialize(id, balance=100, opendate)
@id = id
@balance = balance
@opendate = opendate
#@id_field = []
# @id_field = firs
end

def display_account
Expand Down Expand Up @@ -80,9 +78,9 @@ def self.find(id)
end
end
end

end

end
end


# new_user = Bank::Owner.new("Andre")
Expand Down
92 changes: 92 additions & 0 deletions BankAccount.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
require 'csv'
# Create a module with the name Bank that will contain the class Account
module Bank
# Create an Account class

class Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Watch your indentation here. The Owner class is inside of the Bank module so should be indented one additional level


attr_accessor :name

def initialize(name)
@name = name
#@balance = balance
puts "Hello, #{@name}."
end
end

class Account

attr_reader :account_id, :balance, :opendate
# set my deafualt balance to 100
def initialize(id, balance, opendate)
if balance < 0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One extra level of indent here

raise ArgumentError, "Your balance is negative!"
end
@id = id
@balance = balance
@opendate = opendate
end

def display_account
# show balance of account at initial start
# show the account id
puts @balance
end

def withdraw(amount)
# accepts single parameters that represents the amount to be withdraw
# return updated balance
## balance sets up the method that will subtract the amount from the balance
## have the (-) subtracts from the set from below variable
if @balance - amount < 0
puts "You have a negative balance!"
puts "Please deposit money into your account."
else
@balance -= amount
puts @balance
end
return @balance
end


def deposit(amount)
# accept single parameter that represents the amount of money to be depostied
@balance += amount

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of the += here

# should return updated account balance
puts @balance
end

def self.all
# open a file and puts it in the variable back_csv
# read tells it to format the text.
# puts the whole thing in an array, puts the lines in little arrays.
bank_csv = CSV.read("./support/accounts.csv")
# displaying the content
print bank_csv

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend removing the printing of the CSV because the method should return the contents of the data instead

# This will make sure the content of the file is spit out.
# need to put all the info into the accounts and then return the accounts.
# This gives you access to each little array
bank_csv.map do |acct_info|
puts acct_info
Account.new(acct_info.first, acct_info[1].to_i, acct_info[2])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will account_info.first do in this case?

end
end

def self.find(id)
accounts = self.all
accounts.each do |account|
if account.id == id
return account
end
end
end

end
end


# new_user = Bank::Owner.new("Andre")
# new_account = Bank::Account.new(1234, 2000)
# new_account.display_account
# new_account.withdraw(60)
# new_account.deposit(150)
93 changes: 93 additions & 0 deletions BankClass.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
require 'csv'
reqiure "./SavingAccount.rb"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a typo in your require

require "./CheckingAccount.rb"

# Create a module with the name Bank that will contain the class Account
module Bank
# Create an Account class

class Owner

attr_accessor :name

def initialize(name)
@name = name
#@balance = balance
puts "Hello, #{@name}."
end
end

class Account

attr_reader :account_id, :balance, :opendate
# set my deafualt balance to 100
def initialize(id, balance=100, opendate)
if balance < 0
raise ArgumentError, "Your balance is negative!"
end
@id = id
@balance = balance
@opendate = opendate
end

def display_account
# show balance of account at initial start
# show the account id
puts @balance
end

def withdraw(amount)
# accepts single parameters that represents the amount to be withdraw
# return updated balance
## balance sets up the method that will subtract the amount from the balance
## have the (-) subtracts from the set from below variable
@balance -= amount
puts @balance
if @balance - amount < 0
puts "You have a negative balance!"
puts "Please deposit money into your account."
end
end


def deposit(amount)
# accept single parameter that represents the amount of money to be depostied
@balance += amount
# should return updated account balance
puts @balance
end

def self.all
# open a file and puts it in the variable back_csv
# read tells it to format the text.
# puts the whole thing in an array, puts the lines in little arrays.
bank_csv = CSV.read("./support/accounts.csv")
# displaying the content
print bank_csv
# This will make sure the content of the file is spit out.
# need to put all the info into the accounts and then return the accounts.
# This gives you access to each little array
bank_csv.map do |acct_info|
puts acct_info
Account.new(acct_info.first, acct_info[1].to_i, acct_info[2])
end
end

def self.find(id)
accounts = self.all
accounts.each do |account|
if account.id == id
return account
end
end
end

end

require "./SavingAccountclass.rb"

# new_user = Bank::Owner.new("Andre")
# new_account = Bank::Account.new(1234, 2000)
# new_account.display_account
# new_account.withdraw(60)
# new_account.deposit(150)
3 changes: 3 additions & 0 deletions BankRequireFiles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require "./Bank.rb"
require "./SavingAccount.rb"
require "./CheckingAccount.rb"
26 changes: 26 additions & 0 deletions CheckingAccount.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module Bank

class CheckingAccount < Account

attr_reader :balance
# set my deafualt balance to 100
def initialize(id, balance, opendate)
super
@withdraw_fee = 1
@checks_wdrawn = 0
end

def withdraw_using_check(amount)
if @checks_wdrawn > 3
@balance -= 2
end
if @balance - amount < -10
puts "warning"
else
@balance -= amount
end
@checks_wdrawn += 1
return @balance
end
end
end
30 changes: 14 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,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

<!--
## Wave 3
Create a `SavingsAccount` class which should inherit behavior from the `Account` class. It should include updated logic with the following functionality:
- An updated `initialize` method:
- The initial balance cannot be less than $10. If it is, this will `raise` an `ArgumentError`
- An updated `withdraw` method:
Create a `SavingsAccount` class which should inherit behavior from the `Account` class. It should include the following updated functionality:
- The initial balance cannot be less than $10. If it is, this will `raise` an `ArgumentError`
- Updated withdrawal functionality:
- Each withdrawal 'transaction' incurs a fee of $2 that is taken out of the balance.
- Does not allow the account to go below the $10 minimum balance - Will output a warning message and return the original un-modified balance

It should include the following new methods:
It should include the following new method:
- `#add_interest(rate)`: Calculate the interest on the balance and add the interest to the balance. Return the **interest** that was calculated and added to the balance (not the updated balance).
- Input rate is assumed to be a percentage (i.e. 0.25).
- The formula for calculating interest is `balance * rate/100`
- Example: If the interest rate is 0.25% and the balance is $10,000, then the interest that is returned is $25 and the new balance becomes $10,025.

Create a `CheckingAccount` class which should inherit behavior from the `Account` class. It should include updated logic with the following functionality:
- `#withdraw(amount)`: The input amount gets taken out of the account as result of an ATM transaction. Each withdrawal 'transaction' incurs a fee of $1 that is taken out of the balance. Returns the updated account balance.
- Does not allow the account to go negative. Will output a warning message and return the original un-modified balance.
Create a `CheckingAccount` class which should inherit behavior from the `Account` class. It should include the following updated functionality:
- Updated withdrawal functionality:
- Each withdrawal 'transaction' incurs a fee of $1 that is taken out of the balance. Returns the updated account balance.
- Does not allow the account to go negative. Will output a warning message and return the original un-modified balance.
- `#withdraw_using_check(amount)`: The input amount gets taken out of the account as a result of a check withdrawal. Returns the updated account balance.
- Allows the account to go into overdraft up to -$10 but not any lower
- The user is allowed three free check uses in one month, but any subsequent use adds a $2 transaction fee
Expand All @@ -102,16 +101,15 @@ Create a `CheckingAccount` class which should inherit behavior from the `Account

## Optional:

Create a `MoneyMarketAccount` class with a minimum of 6 specs. The class should inherit behavior from the `Account` class.
Create a `MoneyMarketAccount` class which should inherit behavior from the `Account` class.
- A maximum of 6 transactions (deposits or withdrawals) are allowed per month on this account type
- `self.new(id, initial_balance)`: creates a new instance with the instance variable `id` and 'initial_balance' assigned
- The initial balance cannot be less than $10,000 - this will `raise` an `ArgumentError`
- `#withdraw(amount)`: The input amount gets taken out of the account as result of an ATM transaction. Returns the updated account balance.
- The initial balance cannot be less than $10,000 - this will `raise` an `ArgumentError`
- Updated withdrawal logic:
- If a withdrawal causes the balance to go below $10,000, a fee of $100 is imposed and no more transactions are allowed until the balance is increased using a deposit transaction.
- Each transaction will be counted against the maximum number of transactions
- `#deposit(amount)`. Returns the updated account balance.
- Updated deposit logic:
- Each transaction will be counted against the maximum number of transactions
- Exception to the above: A deposit performed to reach or exceed the minimum balance of $10,000 is not counted as part of the 6 transactions.
- `#add_interest(rate)`: Calculate the interest on the balance and add the interest to the balance. Return the interest that was calculated and added to the balance (not the updated balance). Note** This is the same as the `SavingsAccount` interest.
- `#add_interest(rate)`: Calculate the interest on the balance and add the interest to the balance. Return the interest that was calculated and added to the balance (not the updated balance).
- Note** This is the same as the `SavingsAccount` interest.
- `#reset_transactions`: Resets the number of transactions to zero
-->
30 changes: 30 additions & 0 deletions SavingAccount.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module Bank

class SavingAccount < Account
attr_reader :balance
# set my deafualt balance to 100
def initialize(id, balance, opendate)
super
@withdraw_fee = 2

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that you used a variable to store the information associated with the fee

if balance < 10
raise ArgumentError, "You need more money!"
end
end

def withdraw(amount)
if @balance - amount - @withdraw_fee < 10
puts "Warning, you are about to withdraw your account!"
return @balance
else
super
end
end

def add_interest(rate)
p = @balance * rate/100
@balance = p + @balance
return p
end

end
end
3 changes: 3 additions & 0 deletions bankfiles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require "./BankAccount.rb"
require "./SavingAccount.rb"
require "./CheckingAccount.rb"