MICRO – PROJECT On
“Library management system”
[COMPUTER ENGINEERING]
DEPARTMENT OF COMPUTER
ENGINEERING
A.Y. DADABHAI TECHNICAL
INSTITUTE
Mahuvej Road, B/H old Mariyambai
hospitalKosamba -394120(Gujarat)
Subject Name: AOOP
Subject Code: 4340701
GUIDED BY:
Mr. Nikunj Tailor PREPARED BY:
Maaz Patel : 216010307040
Hanzala Qureshi : 216010307046
Ziya Sheikh : 216010307058
Paresh Solanki : 216010307062
Mohammad V. : 216010307070
Page | 1
Input :
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class LibraryManagementSystem {
private static class Book {
private int id;
private String title;
private String author;
public Book(int id, String title, String author) {
this.id = id;
this.title = title;
this.author = author;
}
public int getId() {
return id;
}
public String getTitle() {
return title;
}
public String getAuthor() {
return author;
}
}
private List<Book> books;
public LibraryManagementSystem() {
books = new ArrayList<>();
}
public void addBook(int id, String title, String author) {
Book newBook = new Book(id, title, author);
books.add(newBook);
System.out.println("Book added successfully.");
}
public void displayBooks() {
System.out.println("Book ID\tTitle\t\tAuthor");
for (Book book : books) {
Page | 2
System.out.println(book.getId() + "\t" + book.getTitle() + "\t\t" + book.getAuthor());
}
}
public void searchBook(String title) {
for (Book book : books) {
if (book.getTitle().equalsIgnoreCase(title)) {
System.out.println("Book found:");
System.out.println("Book ID: " + book.getId());
System.out.println("Title: " + book.getTitle());
System.out.println("Author: " + book.getAuthor());
return;
}
}
System.out.println("Book not found with the given title.");
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
LibraryManagementSystem library = new LibraryManagementSystem();
while (true) {
System.out.println("\nLibrary Management System");
System.out.println("1. Add Book");
System.out.println("2. Display Books");
System.out.println("3. Search Book by Title");
System.out.println("4. Exit");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
scanner.nextLine(); // Consume the newline left by nextInt()
switch (choice) {
case 1:
System.out.print("Enter Book ID: ");
int id = scanner.nextInt();
scanner.nextLine(); // Consume the newline left by nextInt()
System.out.print("Enter Book Title: ");
String title = scanner.nextLine();
System.out.print("Enter Book Author: ");
String author = scanner.nextLine();
library.addBook(id, title, author);
break;
case 2:
library.displayBooks();
break;
Page | 3
case 3:
System.out.print("Enter Book Title to search: ");
String searchTitle = scanner.nextLine();
library.searchBook(searchTitle);
break;
case 4:
System.out.println("Exiting Library Management System. Goodbye!");
scanner.close();
System.exit(0);
default:
System.out.println("Invalid choice. Please enter a valid option.");
}
}
}
}
Page | 4
Output :
Page | 5