Last active
December 18, 2015 10:38
-
-
Save jbevarts/5769570 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Account | |
| attr_reader :name,:balance | |
| def initialize(name,balance=100) | |
| @name = name | |
| @balance = balance | |
| end | |
| def display_balance(pin_number) | |
| puts pin_number == pin ? "Balance: $#{@balance}" : pin_error | |
| end | |
| def withdraw(pin_number,amount) | |
| @amount = amount | |
| if pin_number == pin | |
| amount > @balance ? overdraft : withdraw_accepted | |
| else | |
| pin_error | |
| end | |
| end | |
| def overdraft | |
| puts "You cannot withdraw that amount! Please try again" | |
| end | |
| def deposit(pin_number,amount) | |
| if pin_number == pin | |
| @balance += amount | |
| puts "Your balance is now $#{@balance}" | |
| else | |
| pin_error | |
| end | |
| end | |
| private | |
| def pin | |
| @pin = 1234 | |
| end | |
| def withdraw_accepted | |
| @balance -= @amount | |
| puts "Withdrew #{@amount}. New balance: $#{@balance}" | |
| end | |
| def pin_error | |
| puts "Access denied: incorrect PIN" | |
| end | |
| end | |
| jerrys_account = Account.new("USBANK",450) | |
| jerrys_account.withdraw(1234,20) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment