#javaproject Library Management System Project in Java | Book Management application in Java

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome to aj programming solutions so in today's video we are going to start with the book management application or a library management application so here very first we are going to cover these five operations first one is to add the book then show all books after that to show available books and then borrow a book and return a book so after that we are going to perform some validations on the fields okay for example we have the fields as a book id or the book title or author so for for each and every field we are going to perform the validation so for that we are going to use a pattern class in java okay after that whenever we are displaying all the book details that time we are going to use a format method so that our details of the book should be displayed in some format okay and then we will see how we can display the text in some different colors okay so these are some points which we are going to cover in today's video okay now let's run the application and see how our application will look like so as soon as we run the application we will see this menu where we have these five operations and the exit one okay so currently we don't have any book added in our library so if we enter a choice as a 2 which is to show all the books we are going to get a message there are no books available in the library okay now let's add some book in the library so to add the book we have a choice as a one so here we have to enter all the book details so here we are getting the message enter book id if we enter any book id then here we will get some message like sorry please enter valid book id because we have provided the validation for the book id and that validation is book id should be in digit from one to four digits okay so let's enter some valid book id let's suppose 23 then author name if we enter the author name like this then we will get again the message please enter a valid author because author name should be a character it should not contain any digit or a special symbols okay so here let's enter the author as james and the title for the author and title we have provided the same validation so it will not allow any digits so here also we have to enter a characters okay then publish here publish here also we have provided the validation so see here our validation is working perfectly fine and here let's enter the year as a 2022 so once we enter all the details we will get a message book added successfully okay so here whenever we are adding the book first time in the library that time by default the status of the book will be available and as soon as some person will borrow the book from the library then automatically the status of that particular book will become not available okay we are going to see that so now we have added one book if you enter twice as a two you can see the details of that book okay so same way we can add the book and show all books then show available books means let's suppose in our library we have 10 books out of 10 3 books are already borrowed by some students so currently in your library you have seven books which are available to borrow okay so that way we can see available books then how to borrow a book if we enter a choice as a four then here we have to enter the book id which you want to borrow currently we have one book id 23 so let's enter 23 here and as soon as we enter the valid book id we will get the message that book is borrowed successfully and here you can see the details of that book so here if you can see automatically the status should have become not available okay now if you enter a choice as a 2 to show all the book details here then you can see that the status is become not available ok now we can return the book as this book is borrowed by students so if you enter a choice as a file and here you have to enter a book id if you enter any book id it will give us a message we cannot return this book because this book is not available in our library okay now let's enter the 5 and the 23 as a book id so that book was borrowed by the students so we have successfully returned that book and now the status of that book became the available if you enter choice as a two you can see that again the status of that book is become available okay so this way we can perform all these operations and here you can see that data we are able to see in the format because we have used the format method and here if you can see this all this text like id title author publisher and status is displayed in some other colors okay so that also we are going to see how we can change the color of the text okay now let's understand how we have created this application okay so very first let's see the project structure so this is simple java project we have created how we can create the simple java project you just have to go to this file new then project so here just click on the next next and here you have to give some project name and then click on the finish okay so this is the procedure to create the project in java now here we have created this book management app project okay and in this source folder we have these classes and the interfaces okay now let's see very first this book is our pojo class okay so in this book class we have all the details like book id then title author of the book then publish here and the status of the book okay after that we have created the constructor here and then all the getter and setters for each and every field at last we have created the two string method okay so all this thing you don't have to write manually you just have to use the generate here command n and then here you have the options to create all this constructor to string and get a set of methods automatically okay so if you want to create the constructor you just click on the constructor and select all the fields or the fields which you want to add in your constructor okay and if you click on the okay automatically the constructor will be created here okay so this way we can create our pojo class here nothing is logical you just have to write the fields then the default constructor parameterized constructor and the getter setter for each and every field at last we will use the method so that our data we will see in the readable format okay after that let's go to our main class so this main class is having the main method okay so whenever we are running our application very first thing we will see the welcome message and the menu of our application okay so for that we have used the do while loop if you can see here this is the do loop and this is the while inside the do loop we have very first message as welcome to book management application okay and these are the menu although operations which we are going to perform here okay very first one is to add the book then show all books likewise we have this six operations and after that we will ask user to enter the choice okay so for that here we have written this system.out.println statement and then here we will get the input from the user okay so here we are going to use the switch case for each and every operation so here we will be having a six cases for the sixth operation very first case is to add a book so here we have used service dot ad book so this service is the if you go to here so this service is the object of the book service interface okay if we go to book service interface this interface contain this five operations okay so add book method then show all books show all available books then borrow a book and return book you can add any other methods here then same thing you have to implement in your implementation class as well so this is the book service implementation class okay so this is implementing the book service interface okay so if we go to the interface we have the first method as a ad book now let's see what is the logic we have written inside the ad book okay so see here this is our ad book method so here we have written the all the details of the book like book id author title and year okay so whenever we are entering the book detail we have to validate that as well for that we have written one more class validator here and inside this validator class we have written the separate methods to validate the entered detail like if user is entering the id book id that book id should be in digits only it should not contain any characters or the special symbols so that validation we have written inside this validator class okay so that's why in this implementation class we have created the object of the validator class this way validator validator is equal to new validator and using this object we can access all the methods which are written in the validator class okay so if we go to the first method which is to add a book so see here what we have done here string book id then validator dot validate id so if we go to this validate id method here we have returned the logic for the validation so very first we will ask user to enter a book id then as soon as user enter a book id here we have used the pattern class okay so see here at line number seven we have written private static pattern id pattern and this pattern have the compile method where we have written this pattern like this id should be digit and it should contain any one to four digits okay so here we will write if condition that if entered input means this book id if that book id is not matching with the pattern you have mentioned above then you can give the message that sorry please enter a valid book id okay otherwise you can break and after this why you can just return the book id okay so this red is we have written to show this message in the red color and if you go above see here this is the code for the for displaying the text in the red color okay so there are different colors and different color codes which we can use so this is for the red one and this is to reset back if we are not resetting then this all the messages should be displayed in the red color okay so that's why here i have written like a red at a first then the message and at last we have written as a reset okay so this way we can validate the book id now same way we have to validate the author and title and the publisher as well so let's see the validation first here for the author and title so we have mentioned the pattern that the author and title should contain only characters and the space it should not contain any digits so that's why this should be the pattern here and for the year as well we have written the pattern that here should be any four digits okay so it will not allow the one digit two three or any uh digit which is more than four okay so here this is the method we have written to validate the author and title okay this is the while loop so here we have written the same method to validate author and title that's why this if else condition we have written like if the input input is a parameter which we are going to pass whenever we are calling this validate author title method okay so if this input is a title then user will see the message enter title if the input is author or other than title then it should give the message as enter order okay so here we will get the result miss whatever input user is entering and then if that input means if user entered the author name or the title of the book then here we have to check the pattern okay so here if this entered the entire title or the author is not matching with the conditions or the validation which we have written then we will again give the message that please enter a valid author or the title okay otherwise we will break come out of the loop and return the result same way we have performed the validation for the year as well this is exactly the same way so very first just we have to enter the year then we have to match with our pattern if it is not matching we will display the message otherwise we will just return the year okay so this way we can write the validations in the separate validator class then in the book implementation class here we will get the book id author title and year and at the first if we are adding any book to your library then the status of that book by default will be available okay and if someone is borrowing that book that time the status of book will automatically become not available okay so here i am passing available whenever you are adding the book okay so here we have uh created the list of the book and inside this list of book we are going to add all the book details as soon as you enter all the details then you will see one message book added successfully and this message you will able to see in the green color so for that green we have the code here so this is the code for the green color okay so this way we can add the book now if we go to the main class very first operation is to add the book i hope you have understood the flow of adding the book now if we enter the application so let's run the application and see so very first one is to add the book okay so enter the one and if we are entering the id in the character it will give the message okay so let's enter the valid book id then author pqr and the title let's keep it as java publish here let's keep it 2022 okay so see here we are able to see book added successfully message okay so now we are done with the first operation to add a book the second one is to show all the books okay so to show all the books what we have to do very first in our main class we have to go to the case 2 and we have to call the show all books methods so this show all books method is available in our book service interface also we have implemented this in our implementation class okay so in this implementation class what we have to do we have to take all the books from the list of the book so see here this is our list of book so in this books we have all the book details so just we have to write the for loop this way like for book this is the list of the books we are going to take all the books one by one and just we are going to print the book details okay so here for printing the book details here we have used the format method okay to format very first we have used this like all the like book id then the title author all the fields are the string type so we have written this way and we have printed all the details okay now this is to show all books so see here uh we have taken one flag as well so initially this flag is false if you have any book in your library then that flag will become the true and if you don't have any books in your library and someone is entering a choice as a two that time you will get a message that there are no books available in the library okay so for this purpose we have used this flag variable and accordingly we can display the messages okay so this is to show all the books now the third operation is to show all available books available books means what if you have so many books in your library but some books are already borrowed by the student and some books are available which any user can borrow so that books will be the available books okay so when you enter choice as a three that time you will see only available books not all books okay so here the logic is same you just have to write the for loop and inside this for loop only changes this if condition so in this if condition you will check that if book dot get status is available then only show the details otherwise don't show that book details okay so same thing here also we have used the flag just to check that is there any available book available or available over in your library or not if there is no book then you will see this message okay then to borrow a book to borrow a book the status of the book should be available okay so for that here very first we will ask user to enter a book id which they want to borrow so here we have written book id and this book id we will validate through this validator method validate id okay now we have to take all the books one by one and we have to check that the entered book id is available in our library or not so for that we have written book dot get id dot equals book id means whatever book id is entered is that book id is matching with the our um book id from the library okay if the both the book ids are matching then we will come inside this if condition there is one more condition that if your book status is available then only you can borrow the book otherwise you cannot borrow okay so that two conditions are written in this if condition and after that once that book is available in your library then you will see the message book borrowed successfully okay and as soon as you borrowed the book automatically we are going to set the status of that book to not available because that book is borrowed and that is not available to borrow for the further students okay so that's why we will set the status as a not available and then uh whatever will be that book details that book details we are just printing here okay so this is the logic to borrow the book i hope you understand the logic after that to return a book we have the same logic like we just check here if this we will ask user to enter the book id as soon as user enter the book id then we will see that is that book available in our library also we have to check that is the status of that book is not available this available book is already in your library and how can that book will be returned okay if that book is borrowed by some students then only that student can return that book so that's why we have added this not available status condition as well and if this both the conditions are satisfied then only you can return that book and as soon as you return the book you will see this message book return successfully and then again the status of that book will become the available from the not available because you return the book that book is in your library and now any other student can borrow that book okay and then you will see the message or the details of the book okay so this way you can perform all the operations in your book management application now let's run this application and debug i will show with the debugging so that you can understand so here let's keep the pointers in the main just keep this debug pointers for all the cases and in the implementation class as well we have to uh keep this debug points in every method so that we can understand how the flow is going so here also i will keep one point show our books and add book okay now let's uh okay now first we are able to see that this is our menu okay now enter the choice as a one so one choice is to add a book okay now see here our debug come here at line number 23 so service dot add book okay now if we do the effect then it will go to add book method inside this implementation class okay now here we have to enter the book id so see here we are getting the message enter a book id okay now if we enter book id as a 12 it will ask to enter the author now let's enter the author as james then f8 then title will be java just eff8 publish your will be 2020 okay now see here if we do the effect see here all the books all the book details will be available here see if i click here you can see that id is 12 title james author java published here 2020 and status is available okay now in the line number 24 we are adding all these details into our list of the book okay now let's do the effect now we will see the message book added successfully see the flow see here we got the message now okay now let's do the effect it will come here now break again this loop will loop will execute again we will see the menu and we have to enter the choice so here let's enter the choice as a 2 and f 8 so it will see here the choice is 2 it will go to show all books then again it will come to show all books method in the implementation class so currently the flag is false so it will come here then this for loop will execute and currently in this books we have only one book added so size is one okay now if we do f8 here so see once we uh come inside this for loop then this flag will be true otherwise this flag will be false okay now it will come here change the flag from false to true then it will come outside see here we can see all the book details okay the same way we can debug further again we can enter the choice as a three so it will show all the available books so currently we have like only one book so uh so it will uh show only one book okay so just do the effect it will go and it will show the available books okay now if we do the effect again so here we can see the menu and now let's enter the choice as a borrow book okay so if we enter choice as a four and do the effect it will go in the implementation class and here it will ask to enter a book id okay now if we enter book id or something like this then it will give the message please enter valid book id so here we have to enter the book id which is available in your library and which you can borrow means the status of that book should be available okay so currently we have this 12 as a book id and the status is available so we can borrow this book so let's enter the book id as a 12 here so see here now let's enter the f8 f8 see book dot get id so if you evaluate this here if you evaluate this see what is the value here as a 12 okay so here we have used the equals method and this book id is also 12 so 12 book dot get id dot equals book id so first condition is true okay then the second condition is to check the status of the book if we evaluate this then you can see that the value of the status is also available okay so both the conditions are matching so it will come inside the if then the flag value was false now it will become true if we do f8 see here the flag value became true now then it will print in the green that book borrowed successfully okay so see here you will see the message book borrowed successfully after that immediately you can see all the details of that book okay so if we do f8 we can see all the book details so see here borrowed book details and this is the id title author publisher all the details will be here so borrow book is done now if we come here now only we have to return the book okay so see here menu is displayed again it will ask to enter a choice so here we have to enter the choice as a file so that we can return that book okay so see here the choice is 5 now it will go to this service dot return book then again it will come to the implementation class so for the return book also the conditions are like that book should be available and the status of that book will be not available so that you can return that okay now see here it is asking to enter a book id now if you enter some 12 is a book id which we can return but just read it just enter here a book id as a one so that one book id is not available in your library now see what happened okay see here it will come inside this for loop and here it will check that is that book is available or not so see here that if condition is not satisfied so it came out of this and here the flag is false only because if the condition is true if this condition is true then only this flag is becoming true otherwise the flag will be false and now this condition is not satisfied so because see here the book dot get id if we evaluate that this book dot get id okay now we are uh at the next line so that's why it is not recognizing but book dot get id will be one okay sorry book dot get id means the uh the 12 12 is our book id which is available okay in this list of books but but we have entered the book id as a one so this condition is not matching that's why this if condition will be failed and now it is out of this if condition and here the flag is false okay so that's why it will come here this condition will be true and then we can see this message that we cannot return this book okay so see here if i do f8 it will see that is the flag value is false yes so it will display this message see we cannot return this book okay now if we do effect again we can see the menu and this time we will enter the choices of file and then we will enter the correct book id okay so here let's enter the book id as a 12 so now see here the flag is become true now okay now it will come here set the status is available it will return this book display all the book details okay so this is the flow of book management application i hope you have understood all the details okay so we have covered all the uh five operations so we have covered how we can use the pattern class so this is the validator class in this validator class we have used these patterns for the id validation then authored and title validation and for the publisher validation okay and in the book service implementation class here when we are showing all the book details that time we have used this format method so that our book details should be displayed in some format okay and to display the text or the messages in different colors we have used the color codes so this way we have covered all the four points we have mentioned in the start that we are going to cover in this video and i hope you have understood all the points if you have any questions you can ask in the comment section and i will uh attach the link in the description for the source code as well so that you can cross verify your code okay so thank you for watching if you like this video please share with your friends and don't forget to subscribe the channel thank you
Info
Channel: SJ Programming Solutions
Views: 17,736
Rating: undefined out of 5
Keywords: javaprojects, bookmanagementapplication, finalyearproject, javacoding, sjprogrammingsolutions
Id: 9g4_3bFdhZc
Channel Id: undefined
Length: 35min 27sec (2127 seconds)
Published: Wed Jun 29 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.