• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading in Objects

 
Johnny Donovan
Greenhorn
Posts: 6
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2700
IntelliJ IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;
}
 
Johnny Donovan
Greenhorn
Posts: 6
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much for replying.

My only problem now is how do i get the Books object?
 
Campbell Ritchie
Sheriff
Pie
Posts: 49849
70
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So i could say :

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic