Simplify a CounterPanel that changes a number and displays it with a label.
The starter applies “single responsibility” too literally: incrementing, decrementing, and resetting each have their own class even though all three operations belong to the same concept. Refactor the implementation so cohesive behavior stays together and the genuinely separate presentation responsibility stays separate.
CounterPanel() creates a counter at 0 with the label "Count".int increment() adds one and returns the new value.int decrement() subtracts one and returns the new value. Negative values are allowed.int reset() restores 0 and returns 0.int value() returns the current value.boolean setLabel(String label) changes the display label and returns true. An empty label changes nothing and returns false.String render() returns "<label>: <value>".Keep the public CounterPanel API. Remove the operation classes that add ceremony without representing independent reasons to change.
Input:
Output:
Explanation: Increment and decrement are two operations on the same counter state, not separate responsibilities.
Input:
Output:
Explanation: The formatter owns the label, while resetting remains ordinary counter behavior.
0 <= label.length <= 20100 calls are made across all methods.This starter produces the correct output, but it mistakes methods for responsibilities. Simplify its design without moving display formatting into the numeric state class.
Full marks when one focused state owner keeps the value and implements increment, decrement, reset, and read operations. Lose points heavily for retaining one action or command class per tiny operation.
Full marks when label validation and output formatting are separate from numeric state. Lose points when simplifying the operation classes also pulls presentation into the counter.
Full marks when CounterPanel delegates to a small counter and formatter, preserves exact return values, rejects an empty label, and returns text without printing. Lose points for unnecessary interfaces, factories, registries, or exposed mutable state.
Passing every test is not enough on its own. A submission is accepted only when the design also clears the bar.
| Call | Returns |
|---|---|
| new CounterPanel() | null |
| increment() | 1 |
| increment() | 2 |
| decrement() | 1 |
| value() | 1 |
| render() | "Count: 1" |
All numeric operations act on one cohesive counter state, and the formatter presents its current value.
Run checks these cases. Submit also runs a larger hidden set.

