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.
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.
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.