Created
March 25, 2016 22:04
-
-
Save BinaryPaean/a1a02d7360a7375310ba to your computer and use it in GitHub Desktop.
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
#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