Java Program
/*
* Library Management System in Java
* Demonstrates arrays, loops, condition checking,
* object creation, and simple data handling.
*/
import [Link];
class Book {
private int id;
private String title;
private boolean issued;
public Book(int id, String title) {
[Link] = id;
[Link] = title;
[Link] = false;
}
public int getId() { return id; }
public String getTitle() { return title; }
public boolean isIssued() { return issued; }
public void issueBook() {
if (!issued) {
issued = true;
[Link]("Book issued successfully.");
} else {
[Link]("Book already issued.");
}
}
public void returnBook() {
if (issued) {
issued = false;
[Link]("Book returned successfully.");
} else {
[Link]("Book was not issued.");
}
}
public void display() {
[Link]("ID: " + id + " | Title: " + title + " | Issued: " + issued);
}
}
public class LibraryManagementSystem {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
Book[] books = new Book[50];
int count = 0;
int choice;
do {
[Link]("1. Add Book");
[Link]("2. Display Books");
[Link]("3. Issue Book");
[Link]("4. Return Book");
[Link]("5. Exit");
choice = [Link]();
switch (choice) {
case 1:
[Link]("Enter Book ID: ");
int id = [Link]();
[Link]();
[Link]("Enter Title: ");
String title = [Link]();
books[count++] = new Book(id, title);
break;
case 2:
for (int i = 0; i < count; i++) {
books[i].display();
}
break;
case 3:
[Link]("Enter Book ID to Issue: ");
int issueId = [Link]();
for (int i = 0; i < count; i++) {
if (books[i].getId() == issueId) {
books[i].issueBook();
}
}
break;
case 4:
[Link]("Enter Book ID to Return: ");
int returnId = [Link]();
for (int i = 0; i < count; i++) {
if (books[i].getId() == returnId) {
books[i].returnBook();
}
}
break;
}
} while (choice != 5);
[Link]();
}
}