Here is my visionary of deposit,withdraw and get pin

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>

```

class Account
attr_reader :name, :balance
def initialize(name,balance=100)
@name=name
@balance=balance
end
private
def pin
@pin=1234
end
def pin_error
return “Access denied: incorrect PIN.”
end
public
def deposit(pin_number,amount)
if pin_number==pin
@balance+=amount
puts"Deposit #{amount}.New balance:$#{@balance}."
else pin_error
end
end

def display_balance(pin_number)
    if pin_number==pin 
        puts "Balance:$#{@balance}."
   else pin_error
   end

end
def withdraw(pin_number,amount)
@balance-=amount
if pin_number==pin
if @balance>0
puts"Withdrew #{amount}.New balance:#{@balance}." else puts"You art trying withdrew #{amount},not sufficient fund.New balance:#{@balance}."
end
else puts pin_error
end
end
def get_pin
puts @pin
end
end
checking_account=Account.new(“Armen”,1000)
checking_account.withdraw(1234,900)
checking_account.display_balance(1234)
checking_account.get_pin
checking_account.deposit(1234,188)
checking_account.withdraw(1234,38)
checking_account.withdraw(1234,500)
checking_account.withdraw(1244,38)
please any suggestion,correction,optimization are welcomed. I just wondering is it possible in withdraw method instead if …else use other kind conditional structures. Share with me your thoughts.

<do not remove the three backticks above>
1 Like

Please are you having any issue or just sharing?

The code looks awesome to me.

just sharing,
it works great.only thing If there is some optimization especially in withdraw if …else statement tell me,for me it looks little bit clumsy .thanks

Awesome. I should double like this :smile:

But it gives an error when not sufficient funds, but still deducts the money and makes a new balance?
Shouldnt it either let it be a negative number and not give an error
OR
not let withdraw when amount > balance