• Post Reply Bookmark Topic Watch Topic
  • New Topic

Get Book Written By First Name  RSS feed

 
Harry Peters
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working on a method that is supposed to return the first book object by an author's first name. This class is BookStore and one of the other classes in BlueJ project is Book. My constructor has an array of 20 book objects. No matter what I try, it always returns null. If I remove the last return, BlueJ complains that I'm missing a return statement. How can I code this so that I can properly return what I need? My method is below. Thanks, gang.

 
Junilu Lacar
Sheriff
Posts: 11481
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would a book's title be equal to the author's first name? That's what line 10 is checking. Would you expect to find "Mark" if you checked the titles of all the books written by Mark Twain?
 
Harry Peters
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getAuthor() still gives null. getAuthorName(), still null. getFirstName(), getFullName() are in Name class. getName() is in Author class. Can't find a way to use the name methods.
 
Junilu Lacar
Sheriff
Posts: 11481
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There could be a number of things going on, maybe the array is full of nulls instead of objects or maybe the objects haven't been initialized properly. We can only guess if you don't show us the code that puts Book objects in the array.
 
Harry Peters
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Carey Brown
Saloon Keeper
Posts: 3315
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seeing as how a Book object contains an Author object which contains a Name which contains a first name, I'm going to guess here, that you're looking for something like

Anything more specific would require looking at the Author and Name source code.
 
Harry Peters
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Carey, whadda ya know! It worked. I thought it would be something like that but I didn't put enough methods! I was close but missed something. Thanks a bunch.
 
Carey Brown
Saloon Keeper
Posts: 3315
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
;o)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!