Library Book Management with Class Inheritance
Swift
Medium
classes
Task «Library Book Management with Class Inheritance»
Create a class `LibraryItem` with fields `title` (String), `year` (Int) and a method `description()` that returns a string in the format "Title: \(title), Year: \(year)". Then create a class `Book` that inherits from `LibraryItem`, with an additional field `author` (String). Override the `description()` method so that it returns a string in the format "Book: \(title) by \(author), \(year)". In the main program, read 6 lines: first 3 lines to create a `LibraryItem` object (title, year), then 3 lines to create a `Book` object (title, year, author). Output the results of calling `description()` for each object on separate lines. It is guaranteed that the year is an integer.
Input Format
Six lines: the first line is the name of the first object (LibraryItem), the second is the year of the first object, the third is the name of the second object (Book), the fourth is the year of the second object, the fifth is the author of the second object, and the sixth is an empty line (not used).
Output Format
Two strings: the first is the result of description() for LibraryItem, the second is the result of description() for Book.
Examples
Example 1
INPUT
7
ADD Война и мир Толстой 1869
ADD Преступление и наказание Достоевский 1866
ADD Анна Каренина Толстой 1877
FIND_AUTHOR Толстой
FIND_YEAR 1870
FIND_AUTHOR Пушкин
OUTPUT
Title: Война и мир, Year: 1869
Book: Преступление и наказание by Достоевский, 1866
Example 2
INPUT
6
add 1984 GeorgeOrwell 1949
add BraveNewWorld AldousHuxley 1932
find GeorgeOrwell
borrow 1984
borrow 1984
find GeorgeOrwell
OUTPUT
Title: add, Year: 1984
Book: BraveNewWorld by AldousHuxley, 1932
main.swift