In this task, you will enhance a basic library management system in Kotlin by implementing several functions in the LibraryService
class.
This system allows users to add books to their libraries and search for them by title, author, or genre. The LibraryService
class already contains skeleton methods you must fill out.
Additionally, you are provided with two data classes: Book
and Author
.
- A
Book
contains a title, list of authors, publication date, genre, and ISBN fields. - An
Author
data class has only one field, name.
-
Create an
Author
class with a single fieldname
of typeString
. -
Create a
Book
class with the fields described below. Please put them in the order as follows:-
title
of typeString
; -
authors
of typeList<Author>
; -
publicationYear
of typeInt
; -
genre
of typeString
; -
isbn
of typeString
;
-
-
Implement the
addBook(book: Book)
method to add a new book to the library.
💡Use some collection here. Book duplicates are allowed.
-
Implement the
searchByTitle(title: String): List<Book>
method to return a list of books that contain the given title. The search should be case-insensitive. -
Implement the
searchByAuthor(authorName: String): List<Book>
method to return a list of books written by authors whose names contain the given string. This search should also be case-insensitive. -
Implement the
searchByGenre(genre: String): List<Book>
method to return a list of books that match the given genre exactly, with case-insensitivity.