-
Notifications
You must be signed in to change notification settings - Fork 20
wave 3 and optional features #71
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
base: jlb/master
Are you sure you want to change the base?
Changes from all commits
b79bdfe
26db51f
f798b19
30264c0
39b27bc
149a579
054909f
6d353ae
84d9f92
f373594
ba471ed
5dd392c
1bc8c2f
350a5a4
f3da494
6e3b069
75ec372
6875092
53c828d
e67060e
5748fd9
2f4a4ec
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 |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| .DS_Store | ||
| *.gem | ||
| *.rbc | ||
| /.config | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,58 +1,77 @@ | ||
| require './bank_account' | ||
|
|
||
| # Test 1: Account 1 with positive balance | ||
|
|
||
| account1 = Bank::Account.new(5000) | ||
| puts "Account created with ID ##{account1.id}" | ||
| account1.print_balance | ||
| puts ("*") * 30 | ||
| account1.withdraw(3000) | ||
|
|
||
| puts ("*") * 30 | ||
| account1.deposit(3000) | ||
|
|
||
| puts ("*") * 30 | ||
| account1.print_balance | ||
|
|
||
| # Test 2: Withdrawing more than the balance | ||
| puts ("*") * 30 | ||
| account1.withdraw(30000000) | ||
|
|
||
| # Test 3: Creating an owner | ||
| puts ("*") * 30 | ||
| donald_hash = { | ||
| first_name: "Donald", | ||
| last_name: "Trump", | ||
| address1: "2000 Fashion Show Dr", | ||
| city: "Las Vegas", | ||
| state: "NV", | ||
| zip: "89109", | ||
| } | ||
| donald = Bank::Owner.new(donald_hash) | ||
| puts "New owner created: #{donald.first_name} #{donald.last_name}" | ||
|
|
||
| # Test 4: Creating an account with an owner | ||
| puts ("*") * 30 | ||
| account3 = Bank::Account.new(1000000000000, donald) | ||
| puts "Account created with owner #{account3.formatted_name}" | ||
| account3.print_balance | ||
|
|
||
| # Test 5: Changing the owner of an account | ||
| puts ("*") * 30 | ||
| hillary_hash = { | ||
| first_name: "Hillary", | ||
| last_name: "Clinton", | ||
| address1: "1271 6th Ave", | ||
| city: "New York", | ||
| state: "NY", | ||
| zip: "10020", | ||
| } | ||
|
|
||
| hillary = Bank::Owner.new(hillary_hash) | ||
| account1.assign_owner(hillary) | ||
|
|
||
| # Test 6: Creating account 2 with negative balance | ||
| puts ("*") * 30 | ||
| account2 = Bank::Account.new(-5000) | ||
| puts "Account created with #{account2.id}" | ||
| account2.print_balance | ||
| require './lib/savings' | ||
| require './lib/checking' | ||
| require './lib/mma' | ||
|
|
||
| # # - Money Market Account Tests - | ||
| # mma = Bank::MoneyMarketAccount.new(1, 1000000) # Valid MMA account | ||
| # mma.print_balance | ||
|
|
||
| # # Test withdrawing all of the MMA balance - PASS | ||
| # mma.withdraw(1000000) | ||
| # mma.withdraw(990000) | ||
|
|
||
| # # Test doing more than 6 transactions if the deposit gets account above $10,000 | ||
| # 5.times do | ||
| # mma.deposit(1) | ||
| # end | ||
| # | ||
| # mma.withdraw(20000) | ||
| # mma.deposit(20000) | ||
| # mma.deposit(30000) | ||
|
|
||
|
|
||
| # # Test withdrawing more than 6 times | ||
| # 10.times do | ||
| # mma.withdraw(1000000) | ||
| # end | ||
| # | ||
| # mma.reset_transactions | ||
|
|
||
| # # Test withdrawing to balance below $10,000 | ||
| # 4.times do | ||
| # mma.withdraw(3300000) | ||
| # end | ||
| # | ||
| # # Test depositing and counting transactions below $10,000 | ||
| # 2.times do | ||
| # mma.deposit(5000000) | ||
| # end | ||
|
|
||
| # # Test Money Market interest | ||
| # mma.add_interest(0.25) | ||
| # mma.add_interest(1) | ||
| # | ||
| # mma = Bank::MoneyMarketAccount.new(1, 9999) # Invalid account - not enough funds | ||
|
|
||
| # - Normal Account Tests - | ||
| # account = Bank::Account.new(1, 100) | ||
| # account.print_balance | ||
| # account.withdraw(20) # Regular withdrawal | ||
| # account.withdraw(1100) # Withdrawing too much | ||
|
|
||
| # account = Bank::Account.new(1, -10) # Account below min | ||
|
|
||
| # # - Savings Account Tests - | ||
| # savings = Bank::SavingsAccount.new(1, 100000) | ||
| # savings.print_balance | ||
| # savings.withdraw(20000) # Regular withdrawal | ||
| # savings.withdraw(1000000000) # Withdrawing too much | ||
| # | ||
| # savings = Bank::SavingsAccount.new(1, 10) # Invalid account - Account below min | ||
|
|
||
| # savings.add_interest(1) | ||
|
|
||
| # # - Checking Account Tests - | ||
| # checking = Bank::CheckingAccount.new(1, 10000) | ||
| # checking.print_balance | ||
| # # | ||
| # checking = Bank::CheckingAccount.new(8, -12000) | ||
|
|
||
| # 5.times do | ||
| # checking.withdraw_using_check(600) | ||
| # end | ||
| # | ||
| # checking.reset_checks | ||
| # 2.times do | ||
| # checking.withdraw_using_check(6000) | ||
| # end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,53 +3,79 @@ | |
| # Dependency: Ruby money -- gem install money | ||
| require 'csv' | ||
| require 'money' | ||
| require 'colorize' | ||
| I18n.enforce_available_locales = false | ||
|
|
||
| module Bank | ||
|
|
||
| class Account | ||
| attr_reader :balance, :id, :owner, :open_date | ||
| # Instantiation of object has optional parameters of balance and owner | ||
| def initialize(id, balance, open_date, owner = nil) | ||
| attr_reader :balance, :id, :owner, :open_date, :type | ||
| FEE = 0 | ||
| MIN_BALANCE = 0 | ||
| # Instantiation of object has optional parameters of open_date and owner | ||
| def initialize(id, balance, open_date = "today", owner = nil) | ||
| @owner = owner | ||
| # Creates an ID of random numbers | ||
| @id = id | ||
| # Raises an error with a rescue for a negative initial balance | ||
| if balance < 0 | ||
| begin | ||
| raise ArgumentError.new("You may not create an account with a negative balance.") | ||
| rescue | ||
| puts "Setting balance to a default value of 0." | ||
| @balance = 0 | ||
| end | ||
| else | ||
| @balance = balance | ||
| @id = id.to_i | ||
| @open_date = open_date | ||
| @type = "Standard" | ||
| @balance = balance.to_i | ||
| # Raises an error if the balance is below the minimum balance | ||
| if balance.to_i < self.class::MIN_BALANCE | ||
| raise ArgumentError.new("You may not create an account below the minimum balance.") | ||
| end | ||
| end | ||
|
|
||
| def withdraw(amount) | ||
| if @balance - amount < 0 | ||
| puts "You cannot withdraw more than your account balance." | ||
| # The withdraw method withdraws from the account | ||
| # check_min parameter - BOOLEAN | ||
| # whether to check if the balance minus amount & fee is less than the minimum balance | ||
| # do_penalty parameter - BOOLEAN | ||
| # whether to subtract the fee from the balance | ||
| def withdraw(amount, check_min = true, do_penalty = true) | ||
| if amount < 0 | ||
| puts "You cannot withdraw a negative amount of money." | ||
| else | ||
| puts "Starting balance: " + Money.new(@balance, "USD").format | ||
| puts "Amount withdrawn: " + Money.new(amount, "USD").format | ||
| @balance -= amount | ||
| puts "Updated balance: " + Money.new(@balance, "USD").format | ||
| puts "------#{@type.upcase} WITHDRAWAL------".colorize(:blue) | ||
| # If the withdrawal will put balance below 0, don't do it an output an error | ||
| if @balance - amount < 0 | ||
| puts "You do not have sufficient funds to withdraw that amount." | ||
| # This check is done with standard, checking, and savings accounts | ||
| elsif @balance - (amount + self.class::FEE) < self.class::MIN_BALANCE && check_min | ||
|
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. Nice job using the constant here across each of your classes |
||
| puts "You cannot go below the minimum account balance of " + Money.new(self.class::MIN_BALANCE, "USD").format | ||
| # This section does the actual withdrawal | ||
| else | ||
| puts "Starting balance: " + Money.new(@balance, "USD").format | ||
|
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 there is a bunch of code where you call this same Money logic so it may be a good place to create a method to take care of the formatting for you |
||
| puts "Amount withdrawn: " + Money.new(amount, "USD").format | ||
| # This section is mostly for the money market account. | ||
| # The MMA does not do the penalty(=false) if it is above $10,000 | ||
| # otherwise it incurs a penalty(=true) | ||
| if do_penalty | ||
| puts "Fee: " + Money.new(self.class::FEE, "USD").format | ||
| @balance -= self.class::FEE | ||
| end | ||
| @balance -= amount | ||
| puts "Updated balance: " + Money.new(@balance, "USD").format | ||
| end | ||
| end | ||
| return @balance | ||
| end | ||
|
|
||
| def deposit(amount) | ||
| puts "Starting balance: " + Money.new(@balance, "USD").format | ||
| puts "Amount deposited: " + Money.new(amount, "USD").format | ||
| @balance += amount | ||
| puts "Updated balance: " + Money.new(@balance, "USD").format | ||
| if amount < 0 | ||
| puts "You cannot withdraw a negative amount of money." | ||
| else | ||
| puts "-------#{@type.upcase} DEPOSIT-------".colorize(:blue) | ||
| puts "Starting balance: " + Money.new(@balance, "USD").format | ||
| puts "Amount deposited: " + Money.new(amount, "USD").format | ||
| @balance += amount | ||
| puts "Updated balance: " + Money.new(@balance, "USD").format | ||
| end | ||
| return @balance | ||
| end | ||
|
|
||
| def print_balance | ||
| puts "----PRINTING BALANCE----".colorize(:blue) | ||
| money = Money.new(@balance, "USD") | ||
| puts "The current balance of this account is " + money.format | ||
| puts "The current balance of this #{@type} account is " + money.format | ||
| end | ||
|
|
||
| # Assign an owner to an account | ||
|
|
@@ -93,7 +119,6 @@ def self.all_relationships | |
| end | ||
| return relationships | ||
| end | ||
|
|
||
| end | ||
|
|
||
| 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. I like that you utilized a hash to create the owner object 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. I like that you utilized a hash to create the owner object |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| require './lib/account' | ||
|
|
||
| module Bank | ||
| class CheckingAccount < Account | ||
| MAX_CHECKS = 3 | ||
|
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. I like that you're using constants for these variables |
||
| FEE = 100 | ||
| OVERDRAFT = -1000 | ||
| def initialize(id, balance, open_date = "today", owner = nil) | ||
| super(id, balance, open_date, owner) | ||
| @type = "Checking" | ||
| @fee = 100 | ||
| @num_checks = 0 | ||
| end | ||
|
|
||
| def withdraw_using_check(amount) | ||
| if amount < 0 | ||
| puts "You cannot withdraw a negative amount of money." | ||
| else | ||
| puts "---CHECK WITHDRAWAL---".colorize(:blue) | ||
| # This is a shorthand if-else statement | ||
| @num_checks > 2 ? (penalty = 200) : (penalty = 0) | ||
|
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. Nice use of the single-line conditional here. You could also re-write this as: |
||
| if @balance - amount - penalty >= OVERDRAFT | ||
| puts "Starting balance: " + Money.new(@balance, "USD").format | ||
| puts "Amount withdrawn: " + Money.new(amount, "USD").format | ||
| puts "Too Many Checks Penalty: " + Money.new(penalty, "USD").format | ||
| @balance -= (amount + penalty) | ||
| puts "Updated balance: " + Money.new(@balance, "USD").format | ||
| @num_checks += 1 | ||
| else | ||
| puts "You cannot go below the minimum overdraft balance of " + Money.new(OVERDRAFT, "USD").format | ||
| end | ||
| end | ||
| return @balance | ||
| end | ||
|
|
||
| def reset_checks | ||
| puts "It's the dawn of a new month and your checks are back to 0!" | ||
| @num_checks = 0 | ||
| 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.
Cool use of your colorize knowledge :-)