Skip to content
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

Th/master #65

Open
wants to merge 18 commits into
base: th/master
Choose a base branch
from
74 changes: 74 additions & 0 deletions Owner.rb
Original file line number Diff line number Diff line change
@@ -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)

Choose a reason for hiding this comment

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

I like that you're using a hash here

@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,

Choose a reason for hiding this comment

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

Since you're not re-using these local variables anywhere else, it might make sense to remove the local variables and plug the person_array[1] code directly into the hash creation

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

Choose a reason for hiding this comment

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

Are you assuming that these would both be strings?

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

Choose a reason for hiding this comment

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

You could simplify this to be:
break if account.nil?
using a single-line conditional

break
else
account.set_owner(owner)
owner_accounts_array.push(account)
end
return owner_accounts_array
end
end

end
end
30 changes: 14 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<!--
## 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 @@ -101,16 +100,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
-->
4 changes: 2 additions & 2 deletions bank.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ def self.owner_account
sample = CSV.read("./support/account_owners.csv")

Choose a reason for hiding this comment

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

In the owner code above, I would remove the space between the method name and the open parenthesis so like:
def self.create_owner (person_array) would be def self.create_owner(person_array)

owner_accounts_array =[]

Choose a reason for hiding this comment

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

When you submit code, i'd delete the commented out bits that you were still debugging or working through

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
Expand Down
33 changes: 33 additions & 0 deletions lib/ChackingAccount.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module Bank
require "./account.rb"
class CheckingAccount < Account

attr_accessor :num_checks

def initialize(id, date)
super
@num_checks = 0
end

def withdraw(amount)
super(amount, 100, 0)
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
93 changes: 93 additions & 0 deletions lib/MoneyMarketAccount.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
module Bank
require "./account.rb"

class MoneyMarketAccount < Account

attr_accessor :num_transactions

def initialize(id, date)
super
@num_transactions = 0
end

def initial_balance
super(1000000)
end

def withdraw(amount)
if check_transactions && check_min_balance

Choose a reason for hiding this comment

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

Where is the check_transactions variable set? It seems like it is used as a local variable here but I don't see where it would be assigned a variable prior to this line of code.

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 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 (@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_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

def check_transactions
if @num_transactions < 7
return true
else
return false
end
end

def show_balance
puts "Your current balance is $#{@balance/100}"
end

def check_min_balance
if @balance < 1000000

Choose a reason for hiding this comment

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

It seems like you are regularly comparing against this balance value so I wonder if you could set a variable equal to this (1000000) somewhere rather than using this individual value each time

return false
else
return true
end
end


end
end
73 changes: 73 additions & 0 deletions lib/Owner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
module Bank
require "./account.rb"

class Owner

Choose a reason for hiding this comment

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

It looks like you have more than one version of this class checked in to your PR. This one is in the lib folder and it looks like the other one is outside of the lib folder.


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
Loading