Skip to content

Bank account - wave 2 #41

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

Merged
merged 8 commits into from
Oct 8, 2015
Merged
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
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ Create an `Account` class which should have the following functionality:
- Add an `owner` property to each Account to track information about who owns the account.
- The `Account` can be created with an `owner`, OR you can create a method that will add the `owner` after the `Account` has already been created.

<!--

## Wave 2
### CSV Files!
- Update the `Account` class to be able to handle all of these fields from the CSV file used as input.
- For example, manually choose the data from the first line of the CSV file and ensure you can create a new instance of your Account using that data
- Add the following **class** methods to your existing `Account` class
- `self.all` - returns a collection of `Account` instances, representing all of the Accounts described in the CSV. See below for the CSV file specifications
- `self.find(id)` - returns an instance of `Account` where the value of the id field in the CSV matches the passed parameter
- Update the `Account` class to be able to handle all of these fields from the CSV file used as input.


#### CSV Data File
Bank::Account
Expand All @@ -57,6 +59,21 @@ Create an `Account` class which should have the following functionality:
- `self.all` - returns a collection of `Owner` instances, representing all of the Owners described in the CSV. See below for the CSV file specifications
- `self.find(id)` - returns an instance of `Owner` where the value of the id field in the CSV matches the passed parameter

Bank::Owner
The data, in order in the CSV, consists of:
**ID** - (Fixnum) a unique identifier for that Owner
**Last Name** - (String) the owner's last name
**First Name** - (String) the owner's first name
**Street Addess** - (String) the owner's street address
**City** - (String) the owner's city
**State** - (String) the owner's state

To create the relationship between the accounts and the owners use the `account_owners` CSV file.
The data for this file, in order in the CSV, consists of:
**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:
Expand Down
210 changes: 156 additions & 54 deletions bank.rb
Original file line number Diff line number Diff line change
@@ -1,83 +1,185 @@
require "./Owner.rb"
#{require "./Owner.rb"}
require "csv"

module Bank
class Account
@@count_accounts = 0

attr_accessor :balance, :id, :owner
attr_accessor :id, :balance, :date, :owner

def initialize (owner)
@balance = initial_balance
@id = rand(200)
@owner = owner
def initialize (id, balance, date)
@balance = balance
@id = id
@date = date
@@count_accounts += 1
@owner = nil
#@owner = owner
end


def initial_balance
puts "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$".center(70)
puts "$$$$$$$ Welcome to Tammy's Bank! $$$$$$$".center(70)
puts "How much $$$ would you like to deposit to your new account ?".center(70)
puts "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$".center(70)
money = gets.chomp.to_i
if money < 0
raise ArgumentError.new("You can't deposit negativ amount of money")
money = 0
elsif money == 0
puts "You have 30 days to deposit at least $5"
end
return money
def set_owner (owner)
@owner = owner
end

def withdraw (amount)
if amount > @balance
puts "The maximun amount you can draw is #{@balance} pennies"
else
puts "You had $#{@balance/100}"
@balance = @balance - amount
puts "The update account balance is $#{@balance/100}"
end
#get a row from index and return a new account
def self.create_account (person_array)
account_id = person_array[0].to_i
account_balance = person_array[1].to_i
account_date = person_array[2]
return Bank::Account.new(account_id, account_balance, account_date)
end

def deposit (amount)
if amount < 0
puts "If you want to withdraw, that's a different method :)"
else
@balance = @balance + amount
puts "After you deposited $#{amount/100}"
puts "The update account balance is $#{@balance/100}"
#read the CSV file and row by row use the "creat account" method to create accounts and
#push it to an array - and return it
def self.all
sample = CSV.read("./support/accounts.csv")
accounts = []
sample.each do |row|
account = create_account(row)
accounts.push(account)
end
return accounts
end

def print_balance
puts "Your current balance is $#{@balance}"
def self.find(id)
sample = CSV.read("./support/accounts.csv")
sample.find do |row|
if row[0].to_i == id
return create_account(row)
end
end
end

end

class Owner

attr_accessor :name, :address, :job, :accounts, :id
#
# def initial_balance
# puts "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$".center(70)
# puts "$$$$$$$ Welcome to Tammy's Bank! $$$$$$$".center(70)
# puts "How much $$$ would you like to deposit to your new account ?".center(70)
# puts "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$".center(70)
# # money = gets.chomp.to_i
# # if money < 0
# # raise ArgumentError.new("You can't deposit negativ amount of money")
# # money = 0
# # elsif money == 0
# # puts "You have 30 days to deposit at least $5"
# # end
# # return money
# # end
#
# def withdraw (amount)
# if amount > @balance
# puts "The maximun amount you can draw is #{@balance} pennies"
# else
# puts "You had $#{@balance/100}"
# @balance = @balance - amount
# puts "The update account balance is $#{@balance/100}"
# end
# end
#
# def deposit (amount)
# if amount < 0
# puts "If you want to withdraw, that's a different method :)"
# else
# @balance = @balance + amount
# puts "After you deposited $#{amount/100}"
# puts "The update account balance is $#{@balance/100}"
# end
# end
#
# def print_balance
# puts "Your current balance is $#{@balance}"
# end
#
# end
# end
#
#
class Owner

attr_accessor :id, :last_name, :first_name, :address, :city, :state

def initialize (info_hash)
@name = info_hash [:name]
@id = info_hash [:id]
@last_name = info_hash [:last_name]
@first_name = info_hash [:first_name]
@address = info_hash [:address]
@job = info_hash [:job]
@accounts = []
@id = info_hash[:id]
@city = info_hash [:city]
@state = info_hash [:state]
end

def add_account
account = Bank::Account.new(self)
@accounts.push(account)
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

nemo_hash = {
name: "Nemo",
address: "Seattle",
job: "Student",
id: 1283
}
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

nemo = Bank::Owner.new(nemo_hash)

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])
owner = self.find(row[1])
if account == nil
break
else
account.set_owner(owner)
owner_accounts_array.push(account)
end
end
return owner_accounts_array
end
end
end





#
#
# nemo_hash = {
# name: "Nemo",
# address: "Seattle",
# job: "Student",
# id: 1283
# }
#
# nemo = Bank::Owner.new(nemo_hash)
#
# end
# end
12 changes: 12 additions & 0 deletions support/account_owners.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
1212,25
1213,24
1214,19
1215,14
1216,18
1217,15
15151,17
15152,16
15153,21
15154,20
15155,22
15156,23
12 changes: 12 additions & 0 deletions support/accounts.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
1212,1235667,1999-03-27 11:30:09 -0800
1213,66367,2010-12-21 12:21:12 -0800
1214,9876890,2007-09-22 11:53:00 -0800
1215,919191,2011-10-31 13:55:55 -0800
1216,100022,2000-07-07 15:07:55 -0800
1217,12323,2003-11-07 11:34:56 -0800
15151,9844567,1993-01-17 13:30:56 -0800
15152,34343434343,1999-02-12 14:03:00 -0800
15153,2134,2013-11-07 09:04:56 -0800
15154,43567,1996-04-17 08:44:56 -0800
15155,999999,1990-06-10 13:13:13 -0800
15156,4356772,1994-11-17 14:04:56 -0800
12 changes: 12 additions & 0 deletions support/owners.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
14,Morales,Wanda,9003 Gerald Hill,Honolulu,Hawaii
15,Foster,Shirley,79734 Namekagon Court,Tampa,Florida
16,Taylor,James,9 Portage Court,Winston Salem,North Carolina
17,Ross,Marilyn,0 Delaware Circle,Seattle,Washington
18,Gonzalez,Laura,310 Hauk Street,Springfield,Illinois
19,Cooper,Ruby,99 American Road,Atlanta,Georgia
20,Knight,Helen,3373 American Point,Charlotte,North Carolina
21,Bell,Jessica,06 Kenwood Hill,Lansing,Michigan
22,Sanders,Annie,8113 Sutherland Center,Everett,Washington
23,Berry,Shirley,7 Kings Pass,Cleveland,Ohio
24,King,Kevin,3499 Judy Center,Santa Monica,California
25,Clark,Kathleen,72984 Chive Hill,New York City,New York