Define a Counter class to represent
simple counting devices. It should include the following
methods.
public static void run() {
Counter a = new Counter();
Counter b = new Counter();
a.increment();
IO.println(a.getValue()); // prints ``1''
a.increment();
b.increment();
IO.println(a.getValue()); // prints ``2''
IO.println(b.getValue()); // prints ``1''
}
Write your answer below.
public class Counter {
// : (your code here)
}
public class Counter {
private int val;
public Counter() {
val = 0;
}
public void increment() {
val++;
}
public int getValue() {
return val;
}
}