Question: 6.Programming Problem: a.Create a Counter class that supports the following: i. increment() Increments the counter by one ii. increment(int value) Increments the counter by value;
6.Programming Problem:
a.Create a Counter class that supports the following:
i. increment() Increments the counter by one
ii. increment(int value) Increments the counter by value; value > 1
iii. decrement() Decrements the counter by one
iv. decrement(int value) Decrements the counter by value; value > 1
v. reset() Resets the counter to zero
vi. toString() Used to list the value/values of data members
b. Create a main() method the instantiates the Counter class and demonstrates all of the aforementioned methods.
Sample run for question #6:
$ useCounter
Initial value of Counter: 0
Value of Counter after increment() being called twice: 2
Value of Counter after increment(3): 5
Value of Counter after decrement(2): 3
Value of Counter after decrement(): 2
Value of Counter after reset(): 0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
