• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reading in Objects

 
Greenhorn
Posts: 6
Netbeans IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much for replying.

My only problem now is how do i get the Books object?
 
Marshal
Posts: 79177
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So i could say :

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic