Skip to content

Bank Account Project #48

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 5 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
90 changes: 86 additions & 4 deletions Bank-Account.rb
Original file line number Diff line number Diff line change
@@ -1,10 +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

attr_accessor :name

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

class Account

def initialize(initial_balance)
@internal_id = internal_id
@initial_balance = @initial_balance
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
#@id_field = []
# @id_field = firs
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
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)
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,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 @@ -58,6 +60,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
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