Skip to content

Commit 3142513

Browse files
committed
Merge pull request #21 from noglows/jln/master
Jln/master
2 parents 96d9038 + f5e005e commit 3142513

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

bank.rb

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
module Bank
2+
class Account
3+
4+
attr_reader :balance, :owner
5+
6+
def initialize(id, initial_balance)
7+
#@account_owner = owner.first_name
8+
@id = id
9+
@balance = initial_balance
10+
@owner = nil
11+
12+
# Raises an argument error if the initial balance is less than 0
13+
if initial_balance < 0
14+
raise ArgumentError, "The balance cannot be less than 0."
15+
end
16+
end
17+
18+
def withdraw(amount_to_withdraw)
19+
if (@balance - amount_to_withdraw)< 0
20+
puts "The requested withdrawal is more than the available funds."
21+
puts "You only have $#{@balance} available for withdrawal."
22+
return @balance
23+
else
24+
@balance -= amount_to_withdraw
25+
puts "You have withdrawn $#{amount_to_withdraw}."
26+
puts "Your current balance is $#{@balance}"
27+
return @balance
28+
end
29+
end
30+
31+
def deposit(amount_to_deposit)
32+
@balance += amount_to_deposit
33+
puts "You have deposited $#{amount_to_deposit}."
34+
puts "Your current balance is $#{@balance}."
35+
return @balance
36+
end
37+
38+
def current_balance
39+
puts "The account with ID #{@id} currently has a balance of $#{@balance}."
40+
end
41+
42+
end
43+
44+
class Owner
45+
attr_reader :first_name, :last_name, :street, :city, :state, :zip_code
46+
47+
def initialize(owner_hash)
48+
@first_name = owner_hash[:first_name]
49+
@last_name = owner_hash[:last_name]
50+
@street = owner_hash[:street]
51+
@city = owner_hash[:city]
52+
@state = owner_hash[:state]
53+
@zip_code = owner_hash[:zip_code]
54+
end
55+
56+
def print_owner_details
57+
puts "The owner of this account is #{@first_name} #{@last_name}."
58+
puts "Street: #{@street}"
59+
puts "City: #{@city}"
60+
puts "State: #{@state}"
61+
puts "Zip: #{@zip_code}"
62+
end
63+
64+
end
65+
66+
end

bank_interaction.rb

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
require './bank.rb'
2+
3+
print "What would you like your User ID to be? "
4+
# NEED TO SANITIZE
5+
user_id = gets.chomp
6+
#user_id = "jessica"
7+
8+
print "How much will you be depositing as your initial balance? "
9+
# NEED TO SANITIZE
10+
initial_deposit = gets.chomp.to_i
11+
#initial_deposit = 4000
12+
new_account = Bank::Account.new(user_id,initial_deposit)
13+
14+
# responses not fully sanitized...
15+
print "Would you like to set up your account owner information today? (enter yes or no) "
16+
response = gets.chomp.downcase
17+
if response == 'yes'
18+
owner_hash = Hash.new()
19+
# Not sanitized yet
20+
print "What is your first name? "
21+
owner_first_name = gets.chomp
22+
print "What is your last name? "
23+
owner_last_name = gets.chomp
24+
print "What is your street? "
25+
owner_street = gets.chomp
26+
print "What is your city? "
27+
owner_city = gets.chomp
28+
print "What is your state? "
29+
owner_state = gets.chomp
30+
print "What is your zip code? "
31+
owner_zip = gets.chomp
32+
33+
owner_hash[:first_name] = owner_first_name
34+
owner_hash[:last_name] = owner_last_name
35+
owner_hash[:street] = owner_street
36+
owner_hash[:city] = owner_city
37+
owner_hash[:state] = owner_state
38+
owner_hash[:zip_code] = owner_zip
39+
40+
new_owner_info = Bank::Owner.new(owner_hash)
41+
new_account.add_owner(new_owner_info)
42+
43+
puts "Thanks #{owner_hash[:first_name]}. You successfully added your owner information."
44+
45+
else
46+
puts "Come back another time to enter your account owner information."
47+
end
48+
49+
# already defined owner hash for testing purposes
50+
#owner_hash = {first_name: "Jessica", last_name: "Noglows", street: "2nd Ave", city: "Seattle", state: "WA", zip_code: 98121}

0 commit comments

Comments
 (0)