| Author |
Reading in Objects
|
Johnny Donovan
Greenhorn
Joined: Mar 23, 2011
Posts: 6
|
|
Hi Guys,
So im a little confused.
Say i have 2 Objects - An author object and a book object. Now i have a created class which implements a class which contains all the methods needed to get information for the objects ex. getAuthorName, getAuthorDOB, getBookName, getBookReleaseDate.
Now the book object also contains an authour object .
How would i get all the books written by a specific author using this method?
Sorry i am trying to learn Java in my spare time but i am very confused.
Thanks you
|
 |
Wouter Oet
Saloon Keeper
Joined: Oct 25, 2008
Posts: 2700
|
|
In pseudo-code:
public List<Book> getBooksByAuthor(Author anAuthor) {
List<Book> booksOfAuthor ...
loopAllBooks {
if the author of the book is the same as anAuthor
add to booksOfAuthor
}
return booksofAuthor;
}
|
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
|
 |
Johnny Donovan
Greenhorn
Joined: Mar 23, 2011
Posts: 6
|
|
Thank you so much for replying.
My only problem now is how do i get the Books object?
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32827
|
|
|
You would have to put all your book objects into a List<Book> or a Book[] array when you create them. Then they are available for you to go through and look for the author.
|
 |
Johnny Donovan
Greenhorn
Joined: Mar 23, 2011
Posts: 6
|
|
So i could say :
|
 |
 |
|
|
subject: Reading in Objects
|
|
|