In the application you will build, a borrower randomly chooses books to check out and check in.
For check outs, the book comes from the library's allBooks collection.
For check ins, the book comes from the borrower's myBooks collection.
So a method to randomly choose a book from any BookDictionary collection will be very useful.
Instructions
- In the Class Browser, select the BookDictionary class.
- Select the Methods | New JADE Method... menu.
The JADE Method Definition dialog is displayed.
- Enter chooseBook and click the OK button.
A skeleton method is created ready for you to code.
- Copy and compile the code on the right.
|

chooseBook() : Book;
vars
i : Integer;
iter : Iterator;
bk : Book;
begin
i := app.random(size - 1) + 1;
iter := createIterator;
iter.startAtIndex(i);
iter.next(bk);
return bk; // return the randomly chosen book
epilog
delete iter;
end; |
|