Feedback for these lessons is very much welcome. If you like or hate something about a lesson let us know, either on GitHub, via Mail or just tell us in person ;)
x
B02 - Book and Library
This time we want to create three classes and fill them with some code.1 2
Step 1
Create the following classes:
Library
in the solution folderBook
in the “Media” folder
Step 2
Fill the Book
class with the following members:
- three
string
properties: “Title”, “Autor” and “ISBN”- they have a
get
and aprivate set
- they have a
- a constructor with three parameters: title, autor and isbn
- a method “Search” that searches in its members with a given search query and returns
true
if a member match with the query
Fill the Library
class with the following members:
- a
private
array field ofBook
“books”- the library can only manage 500 books at a time
- a
private int
field “bookCount” that contains the number of books already in the stock - a standard constructor
- a method “Search” that serches through all books with a given search query and returns an array of
Book
- a method “AddNewBook” that adds a given book (as parameter) to the stock of all books of the library
Step 3
Implement (if you haven’t done it yet) the “Search” method in Book
.
Step 4
Now we want to implement the “Search” method in Library
.
This method should only search if the search query has a length greater than 2.
The result array should have the size3 of the numbers of results and not more.
Hint: Maybe you need a temporary array to solve this.
Step 5
Finally we implement the “AddNewBook” method. It should add the new book to the stock of books and save the new book count.