Imagine a small publishing tool whose users can change the look of their text without opening a new editor. One moment they want a heading in uppercase; the next they want a calmer lowercase style or readable title case. The editor should simply hand the text to the selected formatter—it should not contain those formatting rules itself.
The TextEditor context is already implemented in the starter code. Your job is to complete only the strategy family:
TextFormatter defines name() and format(text).UpperCaseFormatter returns the name "upper" and converts all letters to uppercase.LowerCaseFormatter returns the name "lower" and converts all letters to lowercase.TitleCaseFormatter returns the name "title", uppercases the first letter of each word, and lowercases the remaining letters.The supplied editor starts with UpperCaseFormatter, lets callers switch between the three strategies, and delegates every publish call to the active formatter. The tests interact with the editor through this API:
boolean setFormatter(String kind) switches to "upper", "lower", or "title". An unknown name leaves the current formatter unchanged and returns false.String currentFormatter() returns the active strategy's name.String publish(String text) formats the text and counts the publish.int publishCount() returns the number of publishes.Treat each space as a word separator. Preserve repeated spaces exactly, and return an empty string when the input is empty.
Input:
Output:
Explanation: A new editor uses the uppercase formatter, so the text comes back fully capitalised and the publish count moves to 1.
Input:
Output:
Explanation: Title case uppercases the first letter of each word and lowercases the rest, so WORLD becomes World. Switching to lowercase changes the result without touching the editor.
0 <= text.length <= 100100 calls in total are made across all methods.Full marks when each formatting rule is its own class behind one contract, and `publish` calls that contract without knowing which formatter it holds. Lose points heavily when `publish` branches on the formatter name, or when any formatting logic appears inside `TextEditor`.
Full marks when `setFormatter` replaces the held reference so the same editor produces different output afterwards, and an unrecognised name leaves the current formatter in place. Lose points when the formatter is fixed at construction or when an unknown name clears it.
Full marks when title case uppercases the first letter of each word and lowercases the rest, empty text and repeated spaces survive unchanged, and `publishCount` counts every publish. Lose points when a formatter holds editor state or for printing to stdout.
Passing every test is not enough on its own. A submission is accepted only when the design also clears the bar.
| Call | Returns |
|---|---|
| new TextEditor() | null |
| currentFormatter() | "upper" |
| publish("hello world from strategy pattern") | "HELLO WORLD FROM STRATEGY PATTERN" |
| publishCount() | 1 |
A new editor uses the uppercase formatter, so the text comes back fully capitalised and the publish count moves to 1.
Run checks these cases. Submit also runs a larger hidden set.

