I'm really need help with this one. Im totally lost. I have to crete a class that models a Library. It lets the user add, print, borrow and return books to the Library. I guess my problem is that I really do not understand arrays. I needs to create a array of books in the Lib class. I have to ref the books to a generated ID number in a Book Class. I have code all over the place and I have now confused myself. Can anyone take a look at this and please guide me in the correct direction.

Thanks.

First question I have is why are you using doubles when you should probably be using ints?

Second question would be why is everything static? Static members belong to the class rather than to a specific object (instance of the class). The way you have it now, all the libraries would have the same books. So make those un-static.

In your second contructor (the one taking num as a parameter), what does num represent? Your code suggests that it's the number of books in the library, but I'd guess that it should be the max number of books for the library. If my guess is correct, your empty constructor should probably call the second constructor with a default value.

inLib doesn't seem like it should be in the Library class. Do you have a separate Book class? I'm assuming you do, since you try to create an array of Book1. The structure here seems a little confused. You probably want a function like public boolean isInLib(Book b) which checks if the specified book is in the library (this'll require some way to compare Book objects). The static variable inLib probably is not what you really want, since you should be checking if a specific book is in the library or not.

Similarly with the variable addNew, it's probably not needed. The method addNew() will always return true or false; however, the method should probably take a Book as a parameter as well (e.g. public boolean addNew(Book b)). And you should add the book in the next unused index rather than at index 10. Coincidentally, this is really easy to find since you have numOfBooks.

the print functions don't look like they're done yet.

findBook() should again take a book as a parameter, and you'll have to iterate over the Book array to see if the parameter matches something in the array.

borrowBook() again should have a book as a parameter. And for the Book1.status, you might want to rename status to borrowed so that it's more apparent what the variable is for.

You have lots of return statements of the form return someVariable = something;. This is bad form in any language, but I'm pretty sure it's not even valid in Java. For future reference, you should set a variable, then return it's value on the next line typically. In this case, as mentioned, you probably don't need these variables.

Some of this probably won't make sense at first, so post back and we'll see where we're at. ;)

[edit:] I'm about to head to bed though, so I'll check back tomorrow when I get some free time...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.