/*  Exploring Languages with Interpreters and Functional Programming
    Copyright (C) 2019, H. Conrad Cunningham
    Object-Oriented Counting Program in Scala

1234567890123456789012345678901234567890123456789012345678901234567890

2019-01-24: Adapted from CountingOO.py and CountingMod.scala

*/

class CountingOO(var count: Int, maxc: Int) {

    def has_more(c: Int, m: Int): Boolean = c <= m 

    def adv {
        count = count + 1
    }

    def counter {
        while (has_more(count,maxc)) {
            println(count.toString)
            adv
        }
    }
}

class Times2(kount: Int, maxc: Int) extends CountingOO(kount, maxc) {

    override def has_more(c: Int, m: Int) =
        c != 0 && Math.abs(c) <= Math.abs(m)

    override def adv {
        count = count * 2
    }
}


object Counting {

    def main(args: Array[String]) {
        val ctr = new CountingOO(0,10)
        ctr.counter
        val ctr2 = new Times2(-1,10)
        ctr2.counter
    }

}
