File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes java code problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "java code problem" Watch "java code problem" New topic

java code problem

peterx peter

Joined: Nov 02, 2004
Posts: 19
1-I try to put 5 diffent books in my library object but toString() method dose not work if I write like this: bok[].gettitle() but what do I put in the bok array (bok[?]).
2- How do I test the program?
Ta Ri Ki Sun
Ranch Hand

Joined: Mar 26, 2002
Posts: 442
1. Your toString method should loop through all the books it has to get the information about book[0] through to the end.

2. What would you like to test? Your code has problems such as that Book[] never being initialised but essentially that main method at the end is creating a library and adding 5 books, to test further you can add the method getBook(int index OR String isbn etc).
John Bartlett
Ranch Hand

Joined: Jan 25, 2006
Posts: 116
Problem you got is that you need to loop through your array of books.

Also why are you using arrays for such a thing as this, wouldnt it be better to have a dynamic list like an ArrayList? This would mean you would not have to specifiy a size you could jsut add as many books as you like.

O btw dont really think this is an Intermediate question?

I agree. Here's the link:
subject: java code problem
It's not a secret anymore!