Help with constructor problem

I have the following code in Catalogue.java:

   public void addBook(String addTitle, String addAuthor, String addYear)
   {      
      array = books.length;
     
      books[array] = new Book(addTitle, addAuthor, addYear);
   }

It complains on the last line when trying to add a new book to the array.

The constructors in Book.java are:

   public void Book()
   {
     
      title = "";
      author = "";
      year = "";
     
   }
   
   
   public void Book(String aTitle, String aAuthor, String aYear)
   {
     
      title = aTitle;
      author = aAuthor;
      year = aYear;
                 
   }

Can someone tell me why this doesn't work?

thx
adam
AdamJSawyerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sciuriwareCommented:
Delete the word void in the constructor.

;JOOP!
0
sciuriwareCommented:
A constructor must return a new object, thus do not mention a type, just:  "public book(....."

;JOOP!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AdamJSawyerAuthor Commented:
The error returned by JCreator is:

--------------------Configuration: DaRock - j2sdk1.4.1 <Default> - <Default>--------------------
C:\Documents and Settings\Adam\My Documents\!DaRock\Catalogue.java:34: cannot resolve symbol
symbol  : constructor Book (java.lang.String,java.lang.String,java.lang.String)
location: class Book
      books[array] = new Book(addTitle, addAuthor, addYear);
                            ^
1 error

Process completed.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

sciuriwareCommented:
Did you delete the word 'void' in 2 constructors?

Then:

      array = books.length;
     
      books[array] = new Book(addTitle, addAuthor, addYear);

Will fail: obviously 'books' has a length of 'array', so the last index is array-1.

;JOOP!
0
sciuriwareCommented:
................ and heed my last remark.

;JOOP!
0
AdamJSawyerAuthor Commented:
sorry for lack of feedback. Yeah I fixed those constructors and then fiddled the code to work. the guy I was helping was new to programming and wasn't sure about arrays. I set the array to a predetermined size with a constant, and used an index to point to the place the next book was to be created. Thanks for you help

Cheers
Adam
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.