• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Library System

 
Jayvin leabres
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 808
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 3159
33
Google App Engine Java Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 3159
33
Google App Engine Java Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And how come Campbell didnt welcome Jayvin leabres to JavaRanch?

Jayvin leabres, Welcome to JavaRanch!
 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohamed Sanaulla wrote:And how come Campbell didnt welcome Jayvin leabres to JavaRanch? . . .
So you could have that privilege

Or I forgot Sorry
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic