A message inbox stores email, SMS and push messages. Three reports walk over the same messages: one builds previews, one counts characters and one counts how many messages belong to each type.
The message classes and MessageInbox are already provided. Implement only these visitor components:
MessageVisitor declares one visit method for each message type.PreviewVisitor creates one formatted preview per message.CharacterCountVisitor totals the characters stored in each message.MessageTypeCountVisitor counts emails, SMS messages and push messages.The provided MessageInbox exposes this behavior:
MessageInbox() creates an empty inbox.boolean addEmail(String subject, String body) appends an email.boolean addSms(String text) appends an SMS message.boolean addPush(String title, String body) appends a push message.false once 20 messages are stored; otherwise it returns true.int messageCount() returns the number of stored messages.String[] previews() returns the visitor-produced previews in insertion order.int characterCount() returns the total number of characters in message content.String[] typeSummary() returns "email: <n>", "sms: <n>" and "push: <n>" in that order.Preview an email as "EMAIL: <subject> - <body>", an SMS as "SMS: <text>", and a push message as "PUSH: [<title>] <body>".
For the character total, an email contributes its subject and body lengths, an SMS contributes its text length, and a push message contributes its title and body lengths. Separators added by the preview do not count. Empty strings are valid.
MessageInbox is the only type called by the tests. Complete the visitor interface and visitor classes without inspecting a message's runtime type.
Input:
Output:
Explanation: The preview visitor formats each concrete message differently. The character visitor adds 12 characters from the email, 7 from the SMS and 14 from the push message.
Input:
Output:
Explanation: The type-count visitor groups messages by concrete type, while the preview visitor retains insertion order.
0 <= subject.length, body.length, title.length, text.length <= 10020 messages are stored in one inbox.100 calls in total are made across all methods.Full marks when MessageVisitor declares a separate method for every message type and all three visitors implement every method. Lose points heavily when a visitor uses a type check or a stored type string.
Full marks when previews, character counting and type counting are separate visitor classes that each accumulate their own result. Lose points when one visitor derives its answer from another visitor's output.
Full marks when previews preserve insertion order and exact formatting, characterCount includes exactly the documented fields, empty text is handled, and the type summary always uses email, sms, push order. 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 MessageInbox() | null |
| addEmail("Welcome", "Hello") | true |
| addSms("Call me") | true |
| addPush("Sale", "Half price") | true |
| messageCount() | 3 |
| previews() | ["EMAIL: Welcome - Hello","SMS: Call me","PUSH: [Sale] Half price"] |
| characterCount() | 33 |
The preview visitor formats each concrete message differently. The character visitor adds 7 + 5 for the email, 7 for the SMS and 4 + 10 for the push message.
Run checks these cases. Submit also runs a larger hidden set.

