0% found this document useful (0 votes)
20 views5 pages

Library Borrowing System in Java

The Library Borrowing System is a Java application that allows users to manage book borrowing requests using both a queue (FIFO) and a stack (LIFO). Users can add requests, process them, and view waiting lists for both structures through a menu-driven interface. The program continues to run until the user chooses to exit.

Uploaded by

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

Library Borrowing System in Java

The Library Borrowing System is a Java application that allows users to manage book borrowing requests using both a queue (FIFO) and a stack (LIFO). Users can add requests, process them, and view waiting lists for both structures through a menu-driven interface. The program continues to run until the user chooses to exit.

Uploaded by

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

import [Link].

*; // Import tools like Queue, Stack, Scanner

// Main class for the library system

public class LibraryBorrowingSystem {

// Create a queue for FIFO (First-In-First-Out)

Queue<String> queueList = new LinkedList<>();

// Create a stack for LIFO (Last-In-First-Out)

Stack<String> stackList = new Stack<>();

// Scanner to read user input

Scanner scanner = new Scanner([Link]);

// Method to show the main menu

public void showMenu() {

while (true) {

// Print options for the user

[Link]("\nLibrary Borrowing System");

[Link]("1. Add a borrowing request");

[Link]("2. Process request (Queue - FIFO)");

[Link]("3. Process request (Stack - LIFO)");

[Link]("4. View waiting list (Queue)");

[Link]("5. View waiting list (Stack)");

[Link]("6. Exit");

[Link]("Choose an option (1-6): ");


int choice = [Link](); // Read number

[Link](); // Clear leftover input

// Call the right method based on user choice

switch (choice) {

case 1:

addRequest(); // Add a new request

break;

case 2:

processQueue(); // Process using Queue

break;

case 3:

processStack(); // Process using Stack

break;

case 4:

viewQueue(); // Show Queue list

break;

case 5:

viewStack(); // Show Stack list

break;

case 6:

[Link]("Goodbye!");

return; // Exit the loop

default:

[Link]("Invalid choice. Try again.");


}

// Method to add a new borrowing request

public void addRequest() {

[Link]("Enter student name: ");

String name = [Link](); // Read student name

[Link](name); // Add to queue

[Link](name); // Add to stack

[Link](name + " has requested the book.");

// Method to process request using Queue (FIFO)

public void processQueue() {

if (![Link]()) {

String name = [Link](); // Remove from front

[Link]("Queue: Book given to " + name);

} else {

[Link]("Queue is empty.");

// Method to process request using Stack (LIFO)


public void processStack() {

if (![Link]()) {

String name = [Link](); // Remove from top

[Link]("Stack: Book given to " + name);

} else {

[Link]("Stack is empty.");

// Method to view the queue list (FIFO)

public void viewQueue() {

[Link]("Queue Waiting List (First-In-First-Out):");

if ([Link]()) {

[Link]("No students waiting.");

} else {

for (String name : queueList) {

[Link]("- " + name);

// Method to view the stack list (LIFO)

public void viewStack() {

[Link]("Stack Waiting List (Last-In-First-Out):");

if ([Link]()) {

[Link]("No students waiting.");


} else {

for (int i = [Link]() - 1; i >= 0; i--) {

[Link]("- " + [Link](i));

// Main method to start the program

public static void main(String[] args) {

LibraryBorrowingSystem system = new LibraryBorrowingSystem();

[Link](); // Start the menu

You might also like