0% found this document useful (0 votes)
4 views2 pages

Library Management System Java

The document presents a Java program for a Library Management System that allows users to add, display, issue, and return books. It utilizes arrays, loops, and condition checking to manage book data through a simple console interface. The program defines a 'Book' class with methods for issuing and returning books, along with a main class to handle user interactions.

Uploaded by

123456bca987
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Library Management System Java

The document presents a Java program for a Library Management System that allows users to add, display, issue, and return books. It utilizes arrays, loops, and condition checking to manage book data through a simple console interface. The program defines a 'Book' class with methods for issuing and returning books, along with a main class to handle user interactions.

Uploaded by

123456bca987
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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]();
}
}

You might also like