0% found this document useful (0 votes)
3 views8 pages

Programming Assignment Unit 2

The document describes a Java program for a Library Management System that allows users to add, borrow, and return books with error handling for invalid inputs. It provides a user-friendly interface and ensures smooth interactions through prompts and validations. The program serves as a practical example of object-oriented programming in real-world applications.

Uploaded by

nazilaramzi25
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views8 pages

Programming Assignment Unit 2

The document describes a Java program for a Library Management System that allows users to add, borrow, and return books with error handling for invalid inputs. It provides a user-friendly interface and ensures smooth interactions through prompts and validations. The program serves as a practical example of object-oriented programming in real-world applications.

Uploaded by

nazilaramzi25
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

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/

You might also like