Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created December 30, 2015 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/fa6d38fb6740b6c62b67 to your computer and use it in GitHub Desktop.
Save codecademydev/fa6d38fb6740b6c62b67 to your computer and use it in GitHub Desktop.
Codecademy export
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