-
Notifications
You must be signed in to change notification settings - Fork 20
Bank Account Project Wave 3 #54
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: RAA/master
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +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 | ||
|
|
||
| attr_reader :account_id, :balance, :opendate | ||
| # set my deafualt balance to 100 | ||
| def initialize(id, balance, opendate) | ||
| if balance < 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. One extra level of indent here |
||
| raise ArgumentError, "Your balance is negative!" | ||
| end | ||
| @id = id | ||
| @balance = balance | ||
| @opendate = opendate | ||
| 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 | ||
| if @balance - amount < 0 | ||
| puts "You have a negative balance!" | ||
| puts "Please deposit money into your account." | ||
| else | ||
| @balance -= amount | ||
| puts @balance | ||
| end | ||
| return @balance | ||
| end | ||
|
|
||
|
|
||
| def deposit(amount) | ||
| # accept single parameter that represents the amount of money to be depostied | ||
| @balance += amount | ||
|
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 |
||
| # 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 | ||
|
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'd recommend removing the printing of the CSV because the method should return the contents of the data instead |
||
| # 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]) | ||
|
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. What will |
||
| 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) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| require 'csv' | ||
| reqiure "./SavingAccount.rb" | ||
|
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. Looks like a typo in your require |
||
| require "./CheckingAccount.rb" | ||
|
|
||
| # 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 | ||
|
|
||
| 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 | ||
| 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 | ||
|
|
||
| require "./SavingAccountclass.rb" | ||
|
|
||
| # 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) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| require "./Bank.rb" | ||
| require "./SavingAccount.rb" | ||
| require "./CheckingAccount.rb" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| module Bank | ||
|
|
||
| class CheckingAccount < Account | ||
|
|
||
| attr_reader :balance | ||
| # set my deafualt balance to 100 | ||
| def initialize(id, balance, opendate) | ||
| super | ||
| @withdraw_fee = 1 | ||
| @checks_wdrawn = 0 | ||
| end | ||
|
|
||
| def withdraw_using_check(amount) | ||
| if @checks_wdrawn > 3 | ||
| @balance -= 2 | ||
| end | ||
| if @balance - amount < -10 | ||
| puts "warning" | ||
| else | ||
| @balance -= amount | ||
| end | ||
| @checks_wdrawn += 1 | ||
| return @balance | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| module Bank | ||
|
|
||
| class SavingAccount < Account | ||
| attr_reader :balance | ||
| # set my deafualt balance to 100 | ||
| def initialize(id, balance, opendate) | ||
| super | ||
| @withdraw_fee = 2 | ||
|
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 used a variable to store the information associated with the fee |
||
| if balance < 10 | ||
| raise ArgumentError, "You need more money!" | ||
| end | ||
| end | ||
|
|
||
| def withdraw(amount) | ||
| if @balance - amount - @withdraw_fee < 10 | ||
| puts "Warning, you are about to withdraw your account!" | ||
| return @balance | ||
| else | ||
| super | ||
| end | ||
| end | ||
|
|
||
| def add_interest(rate) | ||
| p = @balance * rate/100 | ||
| @balance = p + @balance | ||
| return p | ||
| end | ||
|
|
||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| require "./BankAccount.rb" | ||
| require "./SavingAccount.rb" | ||
| require "./CheckingAccount.rb" |
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.
Watch your indentation here. The
Ownerclass is inside of theBankmodule so should be indented one additional level