0% found this document useful (0 votes)
19 views7 pages

Cs1102 Library Assignment

The document outlines the development of a Library Management System using Java, focusing on managing book inventory through functionalities such as adding, borrowing, and returning books. It emphasizes object-oriented design, data structures, and user interaction, ensuring accurate record-keeping and user experience. The program is structured with modular code and follows best practices for readability and maintainability.
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)
19 views7 pages

Cs1102 Library Assignment

The document outlines the development of a Library Management System using Java, focusing on managing book inventory through functionalities such as adding, borrowing, and returning books. It emphasizes object-oriented design, data structures, and user interaction, ensuring accurate record-keeping and user experience. The program is structured with modular code and follows best practices for readability and maintainability.
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

1

Library Management System

CS 1102-01 Programming 1

Department of Computer Sciences, University of the People

Mr. Ala Shakhatre

February 11, 2026


2

Introduction
This assignment involves the development of a basic library management system using

Java. The program needs to manage books through its system which enables users to add books

and borrow books and return books while maintaining accurate records of book inventory. The

system shows programming concepts through its implementation of object-oriented design and

data structures and effective input processing which enables users to create working software

applications that include interactive features (Oracle, 2025; Eck, 2022).

Java Program: Library Management System

import [Link];
import [Link];
import [Link];

public class LibrarySystem {

private static Map<String, Book> library = new HashMap<>();

static class Book {


String title;
String author;
int quantity;

Book(String title, String author, int quantity) {


[Link] = title;
[Link] = author;
[Link] = quantity;
}
}

public static void main(String[] args) {


Scanner scanner = new Scanner([Link]);
int choice;

do {
[Link]("\n=== Library System Menu ===");
[Link]("1. Add Books");
[Link]("2. Borrow Books");
[Link]("3. Return Books");
[Link]("4. Exit");
[Link]("Enter your choice: ");

while (![Link]()) {
[Link]("Invalid input! Please enter a number from
1 to 4.");
3

[Link]();
}

choice = [Link]();
[Link]();

switch (choice) {
case 1:
addBooks(scanner);
break;
case 2:
borrowBooks(scanner);
break;
case 3:
returnBooks(scanner);
break;
case 4:
[Link]("Exiting Library System. Goodbye!");
break;
default:
[Link]("Invalid choice! Please choose 1-4.");
}

} while (choice != 4);

[Link]();
}

private static void addBooks(Scanner scanner) {


[Link]("Enter book title: ");
String title = [Link]();
[Link]("Enter book author: ");
String author = [Link]();
[Link]("Enter quantity: ");
int quantity = [Link]();
[Link]();

if ([Link](title)) {
[Link](title).quantity += quantity;
[Link]("Updated quantity of \"" + title + "\" to " +
[Link](title).quantity);
} else {
[Link](title, new Book(title, author, quantity));
[Link]("Added new book: \"" + title + "\" by " +
author);
}
}

private static void borrowBooks(Scanner scanner) {


[Link]("Enter book title to borrow: ");
String title = [Link]();

if (![Link](title)) {
[Link]("Error: Book not found in library.");
return;
}
4

[Link]("Enter quantity to borrow: ");


int quantity = [Link]();
[Link]();

Book book = [Link](title);


if (quantity <= [Link]) {
[Link] -= quantity;
[Link]("Successfully borrowed " + quantity + " copies
of \"" + title + "\".");
} else {
[Link]("Error: Not enough copies available. Current
quantity: " + [Link]);
}
}

private static void returnBooks(Scanner scanner) {


[Link]("Enter book title to return: ");
String title = [Link]();

[Link]("Enter quantity to return: ");


int quantity = [Link]();
[Link]();

if ([Link](title)) {
[Link](title).quantity += quantity;
[Link]("Successfully returned " + quantity + " copies
of \"" + title + "\".");
} else {
[Link]("Error: This book does not belong to the
library.");
}
}
}
5

Program Explanation

The Library Management System project was created as a practical demonstration which shows

how Java programming concepts can be used in real-world situations. The system functions as an

interactive tool which enables users to efficiently control their collection of books. The system

uses a HashMap to store books because it needs to organize book information which includes

title and author and quantity details (Oracle 2025). The design enables simple data management

while the system can efficiently expand its capacity to handle more books in the future.

The program functions through a user interface which presents menus to users who want to

access different functions until they choose to leave the program. The design turns user

interaction into an active process which keeps the application active. The system detects whether

the user is adding new books or existing books when new books are added because the system

needs to update inventory records through accurate quantity revisions.

The Library system has established strict procedures for users who want to borrow or return

books in order to preserve accurate library records. Users are prevented from borrowing more

copies than available, and returns are validated to ensure that only books belonging to the system

are accepted. The program establishes reliability through mechanisms which create success and

error messages which enhance user experience.

Throughout the program, coding best practices are emphasized. The code is modular, with

distinct methods handling different functionalities, enhancing readability and maintainability.

Descriptive variable names, consistent indentation, and comprehensive commenting are used to

make the logic transparent. This approach exemplifies how object-oriented principles and data
6

structures can be applied in real-world software, producing a system that is both functional and

elegantly structured (Eck, 2022).

Screenshots showing the outputs


7

References

Oracle. (2025). The Java™ Tutorials. Oracle. [Link]

Eck, D. J. (2022). Introduction to Programming Using Java, 9th Edition. Hobart and William

Smith Colleges.

Common questions

Powered by AI

The Library Management System utilizes object-oriented design principles by defining a Book class to represent book entities with attributes such as title, author, and quantity. This modular approach encapsulates book-specific information within an object, facilitating code organization and reusability. The system employs a HashMap to manage collections of Book objects, illustrating data abstraction and encapsulation. These principles allow the system to efficiently handle inventory operations by focusing on objects and interactions, streamlining management and expansion of the library's book collection .

To improve its capacity and functionality, the Library Management System could incorporate advanced data structures like TreeMap for sorted data retrieval, enhancing search efficiency. Adding user authentication features would securely manage user-specific operations and permissions. Introducing network capabilities could enable cloud-based management, supporting multiple access points and synchronizing real-time data sharing across locations. Integrating multimedia resources and supporting digital formats would expand collection diversity, meeting broader user needs. These enhancements could significantly increase both scalability and versatility .

The program illustrates the application of interactive features by implementing a command-line interface offering menus that display available operations like adding, borrowing, and returning books. This approach converts user interaction into a structured process with immediate feedback through success and error messages. Such interactivity is crucial in a real-world setting as it guides users through system functionalities, ensuring clarity and reducing the learning curve. These features make the software more user-friendly and effective for library management tasks, exemplifying the integration of interactivity in resolving practical challenges .

The Library Management System has employed several mechanisms to prevent errors during book transactions, including checks on book quantity before borrowing and validation of book ownership before returning. These mechanisms are critical in ensuring the system only processes valid transactions, thus maintaining accurate inventory records. They prevent over-borrowing, which could result in false availability, and incorrect returns, which could skew inventory data. Such stringent error prevention measures are essential for sustaining the fidelity and reliability of library records .

Using a HashMap provides several benefits for the Library Management System, such as efficient retrieval and organization of book information with constant-time average operation for add, remove, and look-up functions. This is particularly advantageous for the dynamic management of book inventories as the library expands. The HashMap allows for quick identification and update of book attributes like title, author, and quantity based on keys, which in this case, are book titles. This data structure supports seamless scaling and efficient handling of increased data loads .

Object-oriented principles underpin the maintenance and scalability of the Library Management System by promoting a modular approach where each class represents a component with specific responsibilities. Encapsulation within the Book class and modular methods for operations like adding and borrowing books allow easy updates and integration of new features without impacting existing functionality. This modularity supports parallel development and simplifies debugging, while inheritance and polymorphism can be leveraged to extend system capabilities in future iterations, facilitating scalable growth and evolution of the system .

The user interface design of the Library Management System contributes to its functionality by providing a structured menu that guides users through different operational tasks such as adding, borrowing, and returning books. This menu-driven interface simplifies interaction by presenting clear options, making it accessible even for users with minimal technical knowledge. The iterative feedback mechanism, through success and error messages, dynamically informs users of transaction outcomes, enhancing user engagement and ensuring continuous application operation until the user chooses to exit .

Without comprehensive error validation, users might experience confusion and frustration due to inaccurate library inventory data and improper transaction processing. For instance, borrowing operations without quantity checks could result in negative stock quantities, misleading inventory reports, and affecting availability for other users. Similarly, unverified returns could introduce incorrect data, leading to further mismatches in inventory management. Overall, this lack of validation could undermine the reliability of the system and degrade user trust and experience .

The Library Management System demonstrates best practices in coding through modular design, where distinct methods handle different functionalities such as adding, borrowing, and returning books. This modularity enhances readability and maintainability. Additionally, the use of descriptive variable names and consistent code indentation make the codebase easy to navigate. Comprehensive commenting explains the logic behind code segments, aiding in maintaining and scaling the system. These practices align with software engineering principles to ensure a robust, understandable, and scalable system .

The Library Management System ensures data integrity by implementing strict procedures for borrowing and returning books. For borrowing books, it checks the availability of sufficient quantity before proceeding with a transaction, thus preventing users from borrowing more books than are available. Similarly, for returns, the system verifies whether the book being returned belongs to it, avoiding incorrect inventory updates. These error-checking mechanisms generate success and error messages that inform users of the state of their transactions, maintaining accurate library records at all times .

You might also like