File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Library System Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Library System" Watch "Library System" New topic
Author

Library System

Jayvin leabres
Greenhorn

Joined: Oct 11, 2011
Posts: 2
good day.


hi to all expert in java here. can somebody help me with this code because I'm having a hard time with this. I'm new in java please help
how can i return to main . for example the book i need to display is 19 . but if i entered 20 it will end. my prof. want me to add that if i entered 20 it will have message "THERES NO SUCH BOOK" and display the book list again. please help i really need it thanks in advance.






dennis deems
Ranch Hand

Joined: Mar 12, 2011
Posts: 808
Well, everything that is happening in your main method could be delegated to other methods which perform smaller and more specific tasks. Displaying the book list could be in one method. Acquiring user input could be in another. Searching for the requested book could be a third. And so on. After invoking any of these methods from main, control would be returned to main.

Also, instead of building your book list in main, you could build it in the LibrarySystem constructor, and then it could be an instance field available to any method that might need to use it.

Does that help?
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

First things first: Please UseCodeTags for posting that code, that way they are stand out from the rest of the post content.

The regarding your query- think of on these lines:
Have a infinite while loop which would:
1. Take the input from the user
2. See if its a valid input, if yes then proceed further, allow the user to borrow the book and then break out of the loop indicating that the user has completed the borrow process.
3. otherwise ask the user for input again.

You can break up the code into:
1. Displaying the Books available.
2. Borrowing the book which would check for the availability.


Mohamed Sanaulla | My Blog
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39828
    
  28
Mohamed Sanaulla wrote:. . . Please UseCodeTags for posting that code,. . .
I added code tags, but had to make other changes, because the lines are too long.
You are indenting incorrectly; please have a look at these suggestions about formatting.
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

And how come Campbell didnt welcome Jayvin leabres to JavaRanch?

Jayvin leabres, Welcome to JavaRanch!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39828
    
  28
Mohamed Sanaulla wrote:And how come Campbell didnt welcome Jayvin leabres to JavaRanch? . . .
So you could have that privilege

Or I forgot Sorry
 
 
subject: Library System