1
Library Management System in Java
CS 1102-01 Programming 1 - AY2025-T5
Programming Assignment Unit 2
Instructor: Salah Jabareen
July 3, 2025
2
Library Management System in Java
I present a Java program designed to manage a simple library system. The program allows users
to perform essential functions such as adding books, borrowing books, returning books, and
exiting the application. Each function is implemented with user interaction and error handling to
ensure a smooth experience.
1. Add Books
The program prompts the user to enter the book title, author, and quantity. If the book already
exists in the library, the program updates the quantity. If it is a new book, it adds the book to the
library.
Code Snippet:
Explanation:
This method handles the addition of books. It checks if a book already exists in the library. If it
does, it updates the quantity; if not, it creates a new entry.
3
Output:
2. Borrow Books
Users can borrow books by entering the title and the desired quantity. The program checks if the
requested number of books is available.
Code:
Explanation:
This method allows users to borrow books. It checks whether the requested quantity is available.
If it is, the quantity is updated; otherwise, it displays an error message.
4
Output:
3. Return Books
This feature allows users to return books to the library. Users are prompted to enter the book title
and the number of copies they wish to return.
Code:
Explanation:
This method enables users to return books. It checks if the book exists in the library. If it does,
the quantity is updated successfully; if not, an error message is shown.
5
Output:
4. Error Handling
The program is designed to handle invalid input gracefully. It checks for invalid menu options,
insufficient quantities during borrowing, and attempts to return books that are not in the library.
Code:
6
Explanation:
This method displays a menu for user interaction and handles their choices. It includes error
messages for invalid inputs.
Output:
5. Exit Option
To ensure that users can exit the program at any time, an exit option is provided. This allows for
a clean termination of the program.
Code:
Explanation:
This part of the code allows users to exit the library system gracefully.
Output:
7
In conclusion, the Java library management system effectively implements essential features for
managing books. Through user-friendly prompts and robust error handling, it provides a
seamless experience for users, whether they are adding, borrowing, or returning books. This
program serves as a foundational example of how object-oriented programming can be applied to
real-world scenarios.
8
Reference
Eck, D. J. (2022). Introduction to programming using java version 9, JavaFX edition. Licensed
under CC 4.0. https://math.hws.edu/javanotes/