/* CounterIncreaser.java ** An instance of this odd class is capable, via its run() method, of ** incrementing a given Counter a specified number of times. Both the ** Counter and the number of times to increment it are provided to the ** constructor. (Thus, each time run() is called, that Counter object ** will have its increment() method applied to it the specified number ** of times.) */ public class CounterIncreaser implements Runnable { // instance variables // ------------------ private Counter c; // Counter to be incremented private int n; // # of times to increment that Counter // constructor // ----------- /* Establishes this object as one that, each time its run() method is ** called applies increment() the specified number of times to the ** specified Counter object. */ public CounterIncreaser(Counter counter, int increaseBy) { this.c = counter; this.n = increaseBy; } // run() method // ------------ public void run() { for (int i=0; i != n; i++) { c.increment(); } } }