This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Reading in Objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Reading in Objects" Watch "Reading in Objects" New topic
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: 38472
    
  23
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 :

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading in Objects