OOP Lab Umang
OOP Lab Umang
Keshav Agarwal
Semester: 3rd
3nd Semester
Semester
2320801067
Roll No: 2330802007
Mini-Project: Library
Management System
STAREX UNIVERSITY
GURUGRAM
Problem statement:
To design a system that manages library records, including adding, issuing, and returning
books.
Explanation :
In a Library Management System, the main tasks include:
Solution :
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Scanner;
class Book {
String title;
String author;
boolean isAvailable;
String issuedTo;
class User {
String name;
ArrayList<IssuedBook> issuedBooks;
User(String name) {
this.name = name;
this.issuedBooks = new ArrayList<>();
}
class IssuedBook {
Book book;
LocalDate issueDate;
LocalDate dueDate;
class Library {
private ArrayList<Book> books = new ArrayList<>();
private ArrayList<User> users = new ArrayList<>();
if (!found) {
System.out.println("You have not issued a book with that title.");
}
}
while (true) {
System.out.println("\n1. Add Book\n2. Issue Book\n3. Return Book\n4. Display
Books\n5. View User's Issued Books\n6. Exit");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
scanner.nextLine();
switch (choice) {
case 1:
System.out.print("Enter book title: ");
String title = scanner.nextLine();
System.out.print("Enter book author: ");
String author = scanner.nextLine();
library.addBook(title, author);
break;
case 2:
System.out.print("Enter your name: ");
String userName = scanner.nextLine();
User user = library.addUser(userName);
if (user != null) {
System.out.print("Enter book title to issue: ");
title = scanner.nextLine();
library.issueBook(title, user);
}
break;
case 3:
System.out.print("Enter your name: ");
userName = scanner.nextLine();
user = library.addUser(userName);
if (user != null) {
library.returnBook(user);
}
break;
case 4:
library.displayBooks();
break;
case 5:
System.out.print("Enter your name: ");
userName = scanner.nextLine();
user = library.addUser(userName);
if (user != null) {
library.displayUserIssuedBooks(user);
}
break;
case 6:
System.out.println("Exiting... Thank you for using the library management
system.");
scanner.close();
return;
default:
System.out.println("Invalid choice. Please try again.");
}
}
}
}
Code Explanation :
1. Class Design:
Book: Contains attributes like title, author, isAvailable, and issuedTo. This
class represents a book in the library.
User: Represents a user of the library (a student). This class contains methods
to add and remove issued books and display issued books.
IssuedBook: Represents a book that has been issued to a user, including the
issueDate and dueDate.
Library: Manages all the books and users. This class handles adding books,
issuing books to users, returning books, and displaying books.
LibraryManagementSystem: The main class that implements the
command-line interface for the system.
2. Key Features:
3. Data Structure: