A support desk sends each ticket through a chain of handlers. A specialist accepts tickets in its own category. If it cannot accept a ticket, it passes the ticket to the next handler. The first handler that accepts the ticket returns the response and stops the chain.
The provided SupportDesk exposes this API:
SupportDesk() creates a desk with an empty chain.boolean addHandler(String kind) appends "billing", "technical" or "general" to the end of the chain. It returns false for an unknown kind or a kind already present.String chainOrder() returns handler names from head to tail joined by " -> ", or "EMPTY".String route(String category, String subject) sends a ticket into the chain. A successful response is "<HandlerName>: <subject>". If no handler accepts it, return "UNHANDLED". A category other than "billing", "technical" or "general" returns "INVALID" without entering the chain.int handlerCount() returns the number of handlers in the chain.int handledCount() returns the number of tickets successfully handled across all route calls.The handlers are:
BillingSupport accepts only "billing" tickets.TechnicalSupport accepts only "technical" tickets.GeneralSupport accepts every valid ticket, making it a fallback when it appears late in the chain and a catch-all when it appears early.Complete only the five Chain of Responsibility types left in the starter code:
SupportHandler defines name, setNext, getNext and handle.BaseSupportHandler stores the next handler and centralises forwarding. When there is no next handler, forwarding returns "UNHANDLED".BillingSupport, TechnicalSupport and GeneralSupport implement the acceptance rules above.The supplied desk builds and reports the chain, validates categories, and counts successful routes. SupportDesk is the only type the tests call; do not change it.
Input:
Output:
Explanation: Billing support declines and forwards the ticket. Technical support accepts it and returns immediately, so general support is not reached.
Input:
Output:
Explanation: General support is first and accepts every valid category. The billing handler behind it never sees either ticket.
1 <= subject.length <= 803 handlers are added to one chain.100 calls in total are made across all methods.Full marks when billing, technical and general support are separate handler classes behind one contract, each handler owns its matching rule, and `route` starts at the head without comparing categories. Lose points heavily when the desk uses conditionals to choose a handler directly or walks the chain and performs the matching itself.
Full marks when a specialist forwards only tickets it cannot accept, the general handler accepts every valid ticket, and no handler forwards after producing a response. Lose points when several handlers answer one ticket or when a specialist drops a ticket it cannot handle.
Full marks when handlers are appended in insertion order, unknown and repeated kinds are rejected without changing the chain, an empty chain returns `UNHANDLED`, invalid categories return `INVALID`, and only successful routes increase `handledCount`. Lose points 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 SupportDesk() | null |
| addHandler("billing") | true |
| addHandler("technical") | true |
| addHandler("general") | true |
| chainOrder() | "BillingSupport -> TechnicalSupport -> GeneralSupport" |
| route("technical", "Cannot connect to Wi-Fi") | "TechnicalSupport: Cannot connect to Wi-Fi" |
| handledCount() | 1 |
Billing support declines the technical ticket and forwards it. Technical support accepts it, so general support is never called.
Run checks these cases. Submit also runs a larger hidden set.

