Provided to you is the Java class Counter. Your job is to complete its child class, ReversibleCounter. The idea is that a "reversible counter" is one that can be in either of two modes: normal or reverse. When in the normal mode, it behaves exactly like a "normal" counter (i.e., an instance of the class Counter). When in the reverse mode, calls to increment() and decrement() behave like calls to the opposite one.
Some of the methods (and one constructor) in ReversibleCounter are "stubbed". Some of them include hints about what a good solution would look like.
To test your work, useful would be jGrasp's Workbench utility, as has been demonstrated in class Also available for this purpose is the Java application RevCounterTester. (You are free to modify the test program in any way you see fit.) As illustrated by the sample dialog below, user commands can be in either lower or upper case.
Welcome to the RevCounterTester program. Enter initial count value: 5 After initialization, count value: 5; mode: normal Available commands: ------------------- Q (Quit) H (Help) I (Increment) D (Decrement) T (Toggle the mode) > i count value: 6; mode: normal > I count value: 7; mode: normal > D count value: 6; mode: normal > d count value: 5; mode: normal > d count value: 4; mode: normal > t count value: 4; mode: reverse > i count value: 3; mode: reverse > i count value: 2; mode: reverse > d count value: 3; mode: reverse > d count value: 4; mode: reverse > T count value: 4; mode: normal > i count value: 5; mode: normal > d count value: 4; mode: normal > q count value: 4; mode: normal Goodbye. |