6. Opening an Account


#1

This won't let me pass. The only thing changed from the last question (which let me pass) is the instance created at the bottom. Can anyone help me out?

class Account
attr_reader:name
attr_reader:balance
def initialize(name, balance=100)
@name = name
@balance = balance
private
def pin
def pin_error
return "Access denied: incorrect PIN"

end

end
public
def display_balance(pin_number)
if (pin_number == pin)
puts "Balance $#{@balance}."
else
puts pin_error
end
end
public
def withdraw (pin_number, amount)
if (pin_number == pin)
@balance -= amount
puts "Withdrew #{amount}. New balance: $#{@balance}."
else
puts pin_error
end
end

end

end

checking_account = Account.new("Saltel",100)


#2

Should this read,

def pin
    @pin = 1234
end

?

I went through your code and did find some problems: Compare this to yours to see the differences:

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

#end
  public
  def display_balance(pin_number)
    if (pin_number == pin)
      puts "Balance $#{@balance}."
    else
      puts pin_error
    end
  end
#public
  def withdraw (pin_number, amount)
    if (pin_number == pin)
      @balance -= amount
      puts "Withdrew #{amount}. New balance: $#{@balance}."
    else
      puts pin_error
    end
  end
end

#end

checking_account = Account.new("Saltel",100)

#3

Thanks! I made some changes and it worked!