Skip to content

Instantly share code, notes, and snippets.

@BinaryPaean
Created March 25, 2016 22:04
Show Gist options
  • Save BinaryPaean/a1a02d7360a7375310ba to your computer and use it in GitHub Desktop.
Save BinaryPaean/a1a02d7360a7375310ba to your computer and use it in GitHub Desktop.
#Undef loc var>!
class Account
attr_reader :name
attr_reader :balance
def initialize(name, balance=100)
@name = name
@balance = balance
end
private
def pin
@pin = 1234
end
def pin_error
"Access denied: incorrect PIN."
end
def overdraft_error
"Overdraft is not possible on your account!"
end
public
def display_balance(pin_number)
return pin_error if pin_number != pin
return "Balance :$#{@balance}"
end
def withdraw(pin_number, amount)
return pin_error if pin_number != pin
return overdraft_error if amount > balance
@balance -= amount
end
def deposit(pin_number, amount)
pin_number == pin ? @balance += amount : pin_error
end
def f_withdraw(w_amount)
self.withdraw(1234, w_amount)
end
end
checking_account = Account.new("Mihail",100000)
while true
puts "Choose an action:"
puts "1 - Withdraw"
puts "2 - Deposit"
puts "3 - Display Balance"
puts "4 - Quit\n"
choice = gets.chomp
case choice
when "1"
puts "What amount would you like to withdraw?\n"
w_amount = gets.chomp
puts "Withdrew #{w_amount}. New balance: $#{checking_account.withdraw(1234, w_amount.to_i)}."
when "2"
puts "What amount would you like to deposit?\n"
w_amount = gets.chomp
puts "Deposited #{w_amount}. New balance: $#{checking_account.deposit(1234, w_amount.to_i)}."
when "3"
puts checking_account.display_balance(1234)
when "4"
break
else
puts "Invalid Choice"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment