Scenario

You have been asked again to rescue another project that Mr Lay Zeeman started but did not finish.

The program is for the library of a small club. The library only keeps one copy of each book. When someone borrows a book, the name of the person is recorded as well as the day when they should bring it back.

Some of the work that Mr Zeeman did has been lost.

The project consists of three classes, BookLibrary, and LibraryApplication.

Book

Book objects have fields to store the following data:

· The ID of the book This has the letter F (it is a fiction book) or N (if it is a non-fiction book) followed by 2 digits. e.g. F32

· The author of the book. This has a maximum of 20 characters

· The title of the book. This has a maximum of 40 characters

· The name of the person who has borrowed the boo (If the book is available, then this field is set to null).

Library

The library has only one field that stores a collection (in an Arraylist) of all the books in the library.

The code for the Library class is lost. You will need to write it from scratch.

LibraryApplication

This class is the main library application. It has a field to store the Library object that it is controlling and only one main() method which runs the menu interface of the application.

The code for this class is available and correct. You should not change anything in this class(But you can use examples in this class to answer the questions in your report).

What you need to do:

Restore the project by completing the following coding tasks.

· It is suggested that you do these tasks in the order given as they get progressively difficult.

· It is also suggested that you leave the Challenge suggestions and complete the assignment, coming back to them later if necessary

· It is possible to get up to 70% without completing these

· However, to get a mark above 70%, you will need to make a good attempt at the challenges

Part 1 – make corrections to the Book class

Use comments to show clearly where you have changed Mr Zeeman’s code or added your own.

1. Correct the methods isAvailable() This method always returns fals

Instead, it should only return true when the Borrower is null (which means it has not been borrowed)

Challenge: Write these two methods as efficiently as possible.

1. Correct the method toString().

This method returns a string containing the title of the book.

Instead, it should return the author followed by the title.

Challenge: Format the output as described in the comments

Part 2 – Write the Library class

The library class is completely missing so you have to write this from scratch.

1.Create the Library class, adding a field which will be an ArrayList of Book objects and write the constructor which initialises this field to an empty Ar

Challenge: All through the Library class you should use the correct java coding styles and conventions including correct indentation, suitable variable names in the appropriate case and code comments.(Refer to the guidance in topic 3 / the reference section)

2.In the Library class write the method

addBook(String bookID, String title, String author)

This method should create a new Book object using the parameters and add this to the library.

Challenge: The method should only add the book if the title has a valid format and number of characters.

2. In the Library class write the method listBooks()

This method should list the ID, author and title of all the books in the library, using the toString() method of Book.

Challenge: The output should be user friendly, in clear columns with column titles, and in alphabetical order of the author

4. In the Library class write the method

takeOutBook (String bookID, String borrower)

This method should search the library for the book that has the given bookID and sets the name of the borrower.

Challenge: Once the book has been found, it should not be necessary to keep searching through the remaining book. Also consider what the program should do if the book is not found.

5.In the Library class write the method

returnBook(String bookID)

This method should search the library for the book that has the given bookID and set the book so it is not  borrowed.

Challenge: You should only be able to return the book if the book was already borrowed, otherwise there should be an error message.

6.In the Library class write the method searchForBook(String searchString) This method should search the titles of the books that match the searchString and list the ID, title, author of the book. If the book is borrowed, it should also give the name of the person who has borrowed the book. If the book has not been borrowed it should say “available”.

Challenge:  The user should be able to search for books using part of the title or even wildcards like using *Potter to search for all books where the title ends with Potter.

Your Report:

Write a report with the following 5 sections:

NB: For all code sections use http://www.planetb.ca/syntax-highlight-word (Links to an external site.) to make sure the formatting of your code is maintained (select Java in the options)

Part 1.

Book class: Copy and paste your code for the Book class and change it to suitable fixed-width (monospace) font and font size

Make sure you have used comments to show where you changed the code given.

Part 2.

Library class: Copy and paste your code for the Library class and change it to suitable fixed-width (monospace) font and font siz

Also answer the following questions in your report

Part 3.

For all of the challenge methods write a paragraph in your report describing what you have implemented in the code and justify the methods and algorithms you have selected.

Part 4.

· Array and ArrayList

Your code uses Array and ArrayList objects.

Using examples from your code, explain what an Array and what an ArrayList are, and the similarities and differences between Array objects and ArrayList objects.

Part 5.

Types of Loop

Your code should contain examples of a for loop, a for-each loop and a while loop.

Using examples from your code or other examples, compare different types of loop and explain when each type should be used