public class Counter extends Object implements Comparable<Counter>
For additional documentation, see Section 1.2 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
| Constructor and Description |
|---|
Counter(String id)
Initializes a new counter starting at 0, with the given id.
|
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(Counter that)
Compares this counter to that counter.
|
void |
increment()
Increments the counter by 1.
|
static void |
main(String[] args)
Reads two command-line integers N and T; creates N counters;
increments T counters at random; and prints results.
|
int |
tally()
Returns the current count.
|
String |
toString()
Returns a string representation of this counter
|
public Counter(String id)
id - the name of the counterpublic void increment()
public int tally()
public String toString()
public int compareTo(Counter that)
compareTo in interface Comparable<Counter>public static void main(String[] args)
Copyright © 2014. All Rights Reserved.