Loading...
Loading...
An app sends messages by SMS or email. A counting notifier sits in front of the real channel: it forwards each message and counts messages and parts. The channel can change while the app runs; the counts must not reset.
Write an interface Notifier with int send(String text) (returns the number of parts sent). SmsNotifier splits text into parts of at most 20 characters and prints SMS k/p: PART for each; EmailNotifier prints EMAIL: TEXT and returns 1. CountingNotifier implements Notifier holds another Notifier, delegates to it, counts, and has setChannel(Notifier n).
channel sms, channel email, send TEXT (TEXT is the rest of the line, may contain spaces) or stats. The starting channel is SMS.send; EMPTY for a send with no text (not counted); MESSAGES m PARTS p for stats.Example
Input
5 send Your order is out for delivery channel email send Bill attached send stats
Output
SMS 1/2: Your order is out fo SMS 2/2: r delivery EMAIL: Bill attached EMPTY MESSAGES 2 PARTS 3
The SMS text has 30 characters, so 2 parts; the email is 1 part.
Try the problem first. Open one hint at a time.
Read the command with sc.next(), then the rest of the line with sc.nextLine().trim().
Parts: (length + 19) / 20. Cut part k with substring(k * 20, Math.min(length, k * 20 + 20)).
CountingNotifier.send calls channel.send(text), adds 1 message and the returned parts.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor