Anwesha Java
Anwesha Java
SYSTEM
ASBM UNIVERSITY
SHIKSHA VIHAR, BHOLA, CHANDAKA, BHUBANESWAR-754012, ODISHA
Submitted By:-
Anwesha Priyadarshani
Jyotisankar Rout
Subhasree Muduli
Pravasini Malia
Suryakanta Nayak
Suryasmita Sahoo
Trilokesh Sahu
PROGRAMME: MCA
Submitted To:
Prof.Rasheswari B.Ray
Professor
SIGNATURE
PROJECT 2:-
LIBRARY MANAGEMENTSYSTEM
Project Overview:
The project is a simple system that helps
manage library operations, such as:
Managing books (adding, removing,
searching)
Managing users (registering new users,
deleting users)
Borrowing and returning books
books.
o Admin can register users.
2. Classes/Objects:
o Book: Stores book details such as
book ID, title, author, status
(available/borrowed).
o User: Stores user details such as
user ID, name, and borrowed books.
o Library: Manages operations (add
books, delete books, list books).
o Transaction: Keeps track of book
borrow and return operations.
o Admin: Admin-related operations
like adding/removing users or books.
Step-by-Step Implementation:
1. Create the Book Class:
java
Copy
public class Book {
private int bookId;
private String title;
private String author;
private boolean isAvailable;
// Constructor
public Book(int bookId, String title,
String author) {
this.bookId = bookId;
this.title = title;
this.author = author;
this.isAvailable = true;
}
// Getters and Setters
public int getBookId() {
return bookId;
}
return author;
}
// Constructor
public User(int userId, String name) {
this.userId = userId;
this.name = name;
this.borrowedBooks = new
ArrayList<>();
}
borrowedBooks.add(book);
book.setAvailable(false);
System.out.println("You have
borrowed: " + book.getTitle());
} else {
System.out.println("Sorry, this book
is not available.");
}
}
if (borrowedBooks.contains(book)) {
borrowedBooks.remove(book);
book.setAvailable(true);
System.out.println("You have
returned: " + book.getTitle());
} else {
System.out.println("This book was
not borrowed.");
}
}
// Constructor
public Library() {
this.books = new ArrayList<>();
}
// Add book
books.add(book);
// Remove book
books.removeIf(book ->
book.getBookId() == bookId);
}
// List all books
if (books.isEmpty()) {
System.out.println("No books
available in the library.");
} else {
book.displayBookInfo();
if
(book.getTitle().equalsIgnoreCase(title)) {
return book;
return null;
java
Copy
// Constructor
public Admin(Library library) {
this.library = library;
library.addBook(newBook);
System.out.println("Bookremovedsuc
cessfully.");
java
Copy
import java.util.Scanner;
Scanner sc = new
Scanner(System.in);
Library library = new Library();
while (true) {
System.out.println("\n---- Library
Management System ----");
System.out.println("1. Admin
Login");
System.out.println("3. Exit");
System.out.print("Enter your
choice: ");
switch (choice) {
case 1:
// Admin Login and Operations
System.out.println("AdminLog
ged In");
System.out.println("1. Add
Book");
System.out.println("2.
Remove Book");
System.out.println("3. List
Books");
int adminChoice =
sc.nextInt();
sc.nextLine(); // Consume
newline
if (adminChoice == 1) {
System.out.print("Enter
Book ID: ");
sc.nextLine();
System.out.print("Enter
Book Title: ");
System.out.print("Enter
Book Author: ");
String author =
sc.nextLine();
admin.addNewBook(bookId,
title, author);
} else if (adminChoice == 2) {
System.out.print("Enter
Book ID to remove: ");
int bookId = sc.nextInt();
admin.removeBook(bookId)
;
} else if (adminChoice == 3) {
library.listBooks();
break;
case 2:
if (user == null) {
System.out.print("Enter
User ID: ");
sc.nextLine(); // Consume
newline
System.out.print("Enter User
Name: ");
String name =
sc.nextLine();
System.out.println("1. Borrow
Book");
sc.nextLine(); // Consume
newline
if (userChoice == 1) {
Book book =
library.searchBookByTitle(title);
if (book != null) {
user.borrowBook(book);
} else {
System.out.println("Book not
found.");
} else if (userChoice == 2) {
System.out.print("Enter Book Title to
return: ");
Book book =
library.searchBookByTitle(title);
if (book != null) {
user.returnBook(book);
} else {
System.out.println("Book not
found.");
} else if (userChoice == 3) {
user.displayUserInfo();
break;
case 3:
System.out.println("Exiting...")
;
return;
Additional Improvements:
Conclusion: