AlgoMaster Logo
AlgoMasterPreview a Temporary Alerteasy

Preview a Temporary Alert

easy

An alert desk creates one alert and hands it to a formatter for a preview. The formatter uses that alert during one method call and never stores it.

AlertDesk is provided in the starter code. Its behavior is:

  • String preview(String message, String severity) accepts severities "info", "warning", and "critical".
  • A non-empty message with a supported severity returns "<SEVERITY>:<message>", with the severity label in uppercase.
  • An empty message or unsupported severity returns "INVALID" and changes no state.
  • int previewCount() returns the number of successful previews.
  • String lastSeverity() returns the latest successful lowercase severity, or "NONE" initially.

AlertDesk is provided in the starter code. Do not modify it. Implement two supporting classes:

  • Alert stores the message and severity.
  • A fieldless AlertFormatter.format(Alert alert) builds the output.

AlertDesk may retain only the count and last-severity string. It must not retain an Alert or AlertFormatter.

Example 1:

Input:

Output:

Explanation: The alert exists for one call, the formatter consumes it, and the desk retains only the count and severity string.

Example 2:

Input:

Output:

Explanation: Validation fails before an alert or formatter is needed.

Constraints:
  • 0 <= message.length <= 100
  • 0 <= severity.length <= 20
  • Inputs contain ASCII characters.
  • At most 100 calls are made across all methods.

How the design is graded

needs 7/10 to pass
  • Method-parameter dependency

    Full marks when AlertFormatter.format receives an Alert parameter and AlertFormatter has no fields. Lose points heavily when the formatter stores an alert or AlertDesk absorbs the formatter responsibility.

  • Temporary locals

    Full marks when Alert and the fieldless AlertFormatter expose exactly the constructor and methods used by the provided desk, and the formatter retains no alert. Lose points for incompatible APIs or collaborator fields.

  • Exact behavior

    Full marks when AlertFormatter returns the exact uppercase label and message required by the provided desk without printing to stdout or adding unrelated state.

Passing every test is not enough on its own. A submission is accepted only when the design also clears the bar.

Hints

Loading...
CallReturns
new AlertDesk()null
preview("Disk ready", "info")"INFO:Disk ready"
previewCount()1
lastSeverity()"info"

A temporary alert is passed into the fieldless formatter, and only result data remains.

Run checks these cases. Submit also runs a larger hidden set.