I’m trying to practice and learn by making my first program. I just

started learning about classes so I decided to convert the whole program

so it has a class in it.

It was successful (kinda), but in the end I don’t know why but I’m

getting a nill message between the lines.

Doesn’t nill mean when an outputs value is 0?

Thank you for the help, I appreciate every suggestion!

I’m really enjoying ruby so far.

require_relative ‘font_bold’

class CreditCalculator

def initialize(balance, apr, payment)

@balance = balance

@mpr = Float(apr /12)

@payment = payment

end

def calculate

$m_counter = 0

$total = @balance

```
while @balance > 0
$m_counter += 1
remaining_interest = @balance / 100 * @mpr
$total += remaining_interest
@balance += remaining_interest
@balance -= @payment
principal = @payment - remaining_interest
interest_paid = @payment - principal
if @balance < 0 then @balance = 0 end
interest_paid = interest_paid.round(2)
principal = principal.round(2)
@balance = @balance.round(2)
puts "#{$m_counter.to_s.ljust(7)} #{@payment.to_s.ljust(12)}
```

#{interest_paid.to_s.ljust(17)} #{principal.to_s.ljust(21)}

#{@balance.to_s.ljust(1)}"

puts

end

end

end

puts “Welcome to your credit card payment calculator!”.bold

puts

puts “Please tell me your credit card balance.”

balance = gets.chomp.to_f

puts “Please enter your APR!”

apr = gets.chomp.to_f

puts “How much $ would you like to pay every month?”

payment = gets.chomp.to_f

puts

puts “Month”.ljust(8).bold + “Payment”.ljust(13).bold + “Interest

Paid”.ljust(18).bold + “Principal Paid”.ljust(22).bold + “Remaining

Balance”.bold

debt = CreditCalculator.new(balance, apr, payment)

p debt.calculate

puts

puts “Monthly payment:” + “$”.rjust(3) + “#{payment}”

puts “Balance payoff: #{$m_counter.to_s.rjust(4)} months”

puts “Total payments:” + “$”.rjust(4) + $total.round(2).to_s