JAVA   56
counter
Guest on 5th July 2022 05:12:07 PM


  1. class Counter {
  2.  
  3.    // fields
  4.    private int count;
  5.    private int limit;
  6.  
  7.    // constructor
  8.    Counter(int count, int limit){
  9.       this.count = count;
  10.       this.limit = limit;
  11.    }
  12.  
  13.    // operations
  14.    void click(){
  15.       count = (++count)%limit;
  16.    }
  17.  
  18.    int get(){
  19.       return count;
  20.    }
  21. }

Raw Paste

Login or Register to edit or fork this paste. It's free.