You write an interface and two classes that use it.
Printable is an interface with one method, label(). It returns a short text about the item.
Two classes implement it:
Book(title, author). Its label is the title, thenby, then the author.Ticket(code). Its label isTicket, then the code.
One space separates the words of a label.
In TypeScript, Book and Ticket say implements Printable.
Then write printAll(items). It returns every item's label, in the same order.
The items mix books and tickets. Use each one only through label().
The starter code already has the classes and their constructors. The harness prints each label on its own line.
Example 1:
Input: new Book("Dune", "Herbert"), new Ticket("A12")
Output:
Dune by Herbert
Ticket A12
Explanation: The book joins its title and author with by.
The ticket puts Ticket before its code.
Example 2:
Input: new Ticket("B7"), new Ticket("C3"), new Book("Emma", "Austen")
Output:
Ticket B7
Ticket C3
Emma by Austen
Explanation: The labels keep the order of the items.
Example 3:
Input: new Book("1984", "Orwell")
Output:
1984 by Orwell
Explanation: A title can be digits. It is still text.
Constraints:
- 1 to 100 items.
- Each title, author and code is one word.
- A word has 1 to 20 letters or digits.
Free plan: 30 tutor messages. Premium is unlimited.
