Library Management System
Library Management System
import java.util.ArrayList;
import java.util.Scanner;
class Book {
String title;
String author;
boolean isBorrowed;
this.title = title;
this.author = author;
this.isBorrowed = false;
if (!isBorrowed) {
isBorrowed = true;
} else {
if (isBorrowed) {
isBorrowed = false;
System.out.println("Book returned successfully!");
} else {
@Override
return "Title: " + title + ", Author: " + author + ", Status: " + (isBorrowed ? "Borrowed" : "Available");
class Library {
books.add(book);
if (books.isEmpty()) {
} else {
}
public void removeBook(int index) {
books.remove(index);
} else {
books.get(index).borrowBook();
} else {
books.get(index).returnBook();
} else {
book.author.toLowerCase().contains(keyword.toLowerCase())) {
System.out.println(book);
found = true;
if (!found) {
if (book.isBorrowed) {
System.out.println(book);
found = true;
if (!found) {
if (!book.isBorrowed) {
System.out.println(book);
found = true;
if (!found) {
books.get(index).title = newTitle;
books.get(index).author = newAuthor;
} else {
int choice;
do {
System.out.println("\n Menu");
System.out.println("10. Exit");
System.out.println("\n");
choice = scanner.nextInt();
switch (choice) {
case 1:
break;
case 2:
System.out.println("\nAvailable Books:");
library.viewBooks();
break;
case 3:
library.viewBooks();
library.removeBook(removeIndex);
break;
case 4:
library.viewBooks();
library.borrowBook(borrowIndex);
break;
case 5:
library.viewBooks();
library.returnBook(returnIndex);
break;
case 6:
library.searchBooks(keyword);
break;
case 7:
System.out.println("\nBorrowed Books:");
library.listBorrowedBooks();
break;
case 8:
System.out.println("\nAvailable Books:");
library.listAvailableBooks();
break;
case 9:
library.viewBooks();
break;
case 10:
break;
default:
scanner.close();