# Exploring Languages with Interpreters and Functional Programming
# Copyright (C) 2018, H. Conrad Cunningham

# Object-oriented programming example from Chapter 3

#234567890123456789012345678901234567890123456789012345678901234567890

# 2018-07-04: Developed prototype OO version from modular version

# python3 CountingOO.py

class CountingOO:

    def __init__(self,c,m):
        self.count = c     
        self.maxc  = m

    def has_more(self,c,m):
        return c <= m 

    def adv(self): 
        self.count = self.count + 1
    
    def counter(self):
        while self.has_more(self.count,self.maxc):
            print(f'{self.count}')
            self.adv() 

class Times2(CountingOO):  

    def has_more(self,c,m):
        return c != 0 and abs(c) <= abs(m)

    def adv(self): 
        self.count = self.count * 2

if __name__ == '__main__':
    ctr = CountingOO(0,10)
    ctr.counter()
    ctr2 = Times2(-1,10)
    ctr2.counter()
