Skip to content

Commit 0e54d42

Browse files
committed
Merge pull request #48 from rishallen/RAA/master
Bank Account Project
2 parents 473d20e + ba2c256 commit 0e54d42

File tree

5 files changed

+141
-6
lines changed

5 files changed

+141
-6
lines changed

Bank-Account.rb

+86-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,92 @@
1+
require 'csv'
2+
# Create a module with the name Bank that will contain the class Account
13
module Bank
4+
# Create an Account class
5+
6+
class Owner
7+
8+
attr_accessor :name
9+
10+
def initialize(name)
11+
@name = name
12+
#@balance = balance
13+
puts "Hello, #{@name}."
14+
end
15+
end
16+
217
class Account
318

4-
def initialize(initial_balance)
5-
@internal_id = internal_id
6-
@initial_balance = @initial_balance
19+
attr_reader :account_id, :balance, :opendate
20+
# set my deafualt balance to 100
21+
def initialize(id, balance=100, opendate)
22+
if balance < 0
23+
raise ArgumentError, "Your balance is negative!"
24+
end
25+
@id = id
26+
@balance = balance
27+
@opendate = opendate
28+
#@id_field = []
29+
# @id_field = firs
30+
end
731

32+
def display_account
33+
# show balance of account at initial start
34+
# show the account id
35+
puts @balance
836
end
37+
38+
def withdraw(amount)
39+
# accepts single parameters that represents the amount to be withdraw
40+
# return updated balance
41+
## balance sets up the method that will subtract the amount from the balance
42+
## have the (-) subtracts from the set from below variable
43+
@balance -= amount
44+
puts @balance
45+
if @balance - amount < 0
46+
puts "You have a negative balance!"
47+
puts "Please deposit money into your account."
48+
end
49+
end
50+
51+
52+
def deposit(amount)
53+
# accept single parameter that represents the amount of money to be depostied
54+
@balance += amount
55+
# should return updated account balance
56+
puts @balance
57+
end
58+
59+
def self.all
60+
# open a file and puts it in the variable back_csv
61+
# read tells it to format the text.
62+
# puts the whole thing in an array, puts the lines in little arrays.
63+
bank_csv = CSV.read("./support/accounts.csv")
64+
# displaying the content
65+
print bank_csv
66+
# This will make sure the content of the file is spit out.
67+
# need to put all the info into the accounts and then return the accounts.
68+
# This gives you access to each little array
69+
bank_csv.map do |acct_info|
70+
puts acct_info
71+
Account.new(acct_info.first, acct_info[1].to_i, acct_info[2])
72+
end
73+
end
74+
75+
def self.find(id)
76+
accounts = self.all
77+
accounts.each do |account|
78+
if account.id == id
79+
return account
80+
end
81+
end
82+
end
83+
984
end
10-
end
85+
86+
87+
88+
# new_user = Bank::Owner.new("Andre")
89+
# new_account = Bank::Account.new(1234, 2000)
90+
# new_account.display_account
91+
# new_account.withdraw(60)
92+
# new_account.deposit(150)

README.md

+19-2
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ Create an `Account` class which should have the following functionality:
3636
- Add an `owner` property to each Account to track information about who owns the account.
3737
- 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.
3838

39-
<!--
39+
4040
## Wave 2
4141
### CSV Files!
42+
- Update the `Account` class to be able to handle all of these fields from the CSV file used as input.
43+
- 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
4244
- Add the following **class** methods to your existing `Account` class
4345
- `self.all` - returns a collection of `Account` instances, representing all of the Accounts described in the CSV. See below for the CSV file specifications
4446
- `self.find(id)` - returns an instance of `Account` where the value of the id field in the CSV matches the passed parameter
45-
- Update the `Account` class to be able to handle all of these fields from the CSV file used as input.
47+
4648

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

63+
Bank::Owner
64+
The data, in order in the CSV, consists of:
65+
**ID** - (Fixnum) a unique identifier for that Owner
66+
**Last Name** - (String) the owner's last name
67+
**First Name** - (String) the owner's first name
68+
**Street Addess** - (String) the owner's street address
69+
**City** - (String) the owner's city
70+
**State** - (String) the owner's state
71+
72+
To create the relationship between the accounts and the owners use the `account_owners` CSV file.
73+
The data for this file, in order in the CSV, consists of:
74+
**Account ID** - (Fixnum) a unique identifier corresponding to an account
75+
**Owner ID** - (Fixnum) a unique identifier corresponding to an owner
76+
77+
<!--
6178
## Wave 3
6279
Create a `SavingsAccount` class which should inherit behavior from the `Account` class. It should include updated logic with the following functionality:
6380
- An updated `initialize` method:

support/account_owners.csv

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
1212,25
2+
1213,24
3+
1214,19
4+
1215,14
5+
1216,18
6+
1217,15
7+
15151,17
8+
15152,16
9+
15153,21
10+
15154,20
11+
15155,22
12+
15156,23

support/accounts.csv

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
1212,1235667,1999-03-27 11:30:09 -0800
2+
1213,66367,2010-12-21 12:21:12 -0800
3+
1214,9876890,2007-09-22 11:53:00 -0800
4+
1215,919191,2011-10-31 13:55:55 -0800
5+
1216,100022,2000-07-07 15:07:55 -0800
6+
1217,12323,2003-11-07 11:34:56 -0800
7+
15151,9844567,1993-01-17 13:30:56 -0800
8+
15152,34343434343,1999-02-12 14:03:00 -0800
9+
15153,2134,2013-11-07 09:04:56 -0800
10+
15154,43567,1996-04-17 08:44:56 -0800
11+
15155,999999,1990-06-10 13:13:13 -0800
12+
15156,4356772,1994-11-17 14:04:56 -0800

support/owners.csv

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
14,Morales,Wanda,9003 Gerald Hill,Honolulu,Hawaii
2+
15,Foster,Shirley,79734 Namekagon Court,Tampa,Florida
3+
16,Taylor,James,9 Portage Court,Winston Salem,North Carolina
4+
17,Ross,Marilyn,0 Delaware Circle,Seattle,Washington
5+
18,Gonzalez,Laura,310 Hauk Street,Springfield,Illinois
6+
19,Cooper,Ruby,99 American Road,Atlanta,Georgia
7+
20,Knight,Helen,3373 American Point,Charlotte,North Carolina
8+
21,Bell,Jessica,06 Kenwood Hill,Lansing,Michigan
9+
22,Sanders,Annie,8113 Sutherland Center,Everett,Washington
10+
23,Berry,Shirley,7 Kings Pass,Cleveland,Ohio
11+
24,King,Kevin,3499 Judy Center,Santa Monica,California
12+
25,Clark,Kathleen,72984 Chive Hill,New York City,New York

0 commit comments

Comments
 (0)