-
-
Save codecademydev/fa6d38fb6740b6c62b67 to your computer and use it in GitHub Desktop.
Codecademy export
This file contains 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 | |
private | |
def pin | |
@pin = 1234 | |
end | |
private | |
def pin_error | |
return "Access denied: incorrect PIN." | |
end | |
public | |
def display_balance(pin_number) | |
puts pin_number == pin ? "Balance: $#{@balance}." : pin_error | |
end | |
public | |
def withdraw(pin_number, amount) | |
puts @balance < amount ? "Insufficient funds; desired amount cannot exceed account balance." : "" | |
puts pin_number == pin ? "Withdrew $#{amount}. New balance: $#{@balance}." : pin_error | |
@balance -= amount | |
end | |
public | |
def deposit(pin_number, amount) | |
@balance += amount | |
puts pin_number == pin ? "Deposited #{amount}. New balance: $#{@balance}." : pin_error | |
end | |
#close the class | |
end | |
checking_account = Account.new("Jonathan", 50_000) | |
checking_account.display_balance(1234) | |
checking_account.withdraw(1234, 51000) | |
checking_account.deposit(1244, 10687) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment