How would you call the pin?


#1




private method `pin' called for #<Context::Account:0x00000001707578 @name="cruise", @balance=900>


class Account
    attr_reader :name
    attr_reader :balance
    
    
    def initialize (name, balance=100)
        @name = name
        @balance = balance
    end
    def display_balance (pin_number)
          if pin_number == pin
              puts "Balance: $#{@balance}."
    
          else
              puts pin_error
          end
    end
    def withdraw(pin_number, amount)
        if pin_number = pin
          if amount > balance
              puts "you cannot withdraw the amount"
          else amount <= balance
            balance=balance - amount
            puts "Withdrew #{amount}.  New balance: $#{@balance}."                end
        else 
            puts pin_error
        end
      
    end
    def deposit (pin_number, amount)
        if pin_number = pin
            balance = balance-amount
            puts "Deposited #(amount).  New balance: $#(@balance)."
        else
            puts pin_error
        end
    end
     
    

    private
    def pin
      @pin = 1234
    end
    def pin_error
      "Access denied: incorrect PIN."
    end
end
class Checking_account < Account
end
Checking_account2 = Account.new("cruise", 900)
pinum =Checking_account2.pin


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.