-
Notifications
You must be signed in to change notification settings - Fork 21
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
base: th/master
Are you sure you want to change the base?
Th/master #65
Changes from all commits
2f288d8
b79bdfe
fcbb053
6ad1eef
b2cdbb7
863a0df
2c5d9e6
2ead4c4
d3d3f74
b84d1c7
6ed3a38
c41b9e3
f0116e9
cd8aea4
6eada02
acf1787
c93c8a4
bd8a0e8
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,74 @@ | ||
require "./bank.rb" | ||
require "csv" | ||
module Bank | ||
|
||
class Owner | ||
|
||
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, | ||
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're not re-using these local variables anywhere else, it might make sense to remove the local variables and plug the |
||
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 | ||
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. 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 | ||
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 could simplify this to be: |
||
break | ||
else | ||
account.set_owner(owner) | ||
owner_accounts_array.push(account) | ||
end | ||
return owner_accounts_array | ||
end | ||
end | ||
|
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,8 +152,8 @@ def self.owner_account | |
sample = CSV.read("./support/account_owners.csv") | ||
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. In the owner code above, I would remove the space between the method name and the open parenthesis so like: |
||
owner_accounts_array =[] | ||
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. 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 | ||
|
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 |
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 | ||
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. Where is the |
||
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 | ||
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 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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
module Bank | ||
require "./account.rb" | ||
|
||
class 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. It looks like you have more than one version of this class checked in to your PR. This one is in the |
||
|
||
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 |
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.
I like that you're using a hash here