Advanced Programming Project
Advanced Programming Project
(CSCI217)
Advanced Computer Programming and Concept
Project
Classes Overview
1. library Class:
o Purpose: Represents the library as a collection of books.
o Key Methods:
▪ addbook(book b): Adds a book to the library.
▪ removebook(int id, book b): Removes a book from the library using its ID.
▪ borrow_book(int id, int borrowing_period, book b): Allows borrowing of a
book.
▪ return_book(int id, book b): Returns a borrowed book to the library.
▪ isfull(): Checks if the library has reached its capacity.
▪ displayallbooks(): Displays all the books in the library.
▪ notfound(int id): Throws an exception if the book with the given ID is not
found.
▪ searchBook(String title): Searches for a book by its title.
▪ resetLibrary(): Resets the library, clearing all books and data.
o Attributes:
▪ capacity: The maximum number of books that the library can hold.
▪ totalbooks: The total number of books in the library.
▪ books[]: An array or collection holding the current books in the library.
2. book Class:
o Purpose: Represents a book in the library.
o Key Methods:
▪ setbook_name(String book_name): Sets the book name.
▪ getbook_id(): Returns the book's ID.
▪ getbookname(): Returns the book's name.
▪ setcategory(String category): Sets the category of the book.
▪ getcategory(): Returns the category of the book.
▪ setborrowing_period(int borrowing_period): Sets the borrowing period for
the book.
▪ availability(book k): Checks if the book is available for borrowing.
▪ setreturnn_date(LocalDate returndate): Sets the return date for the book.
▪ getreturnn_date(): Returns the book's return date.
▪ displaybookdetails(): Displays the details of the book.
▪ gettotalbooks(): Returns the total number of books.
o Attributes:
▪ book_name: Name of the book.
▪ book_id: ID of the book.
▪ category: Category of the book (e.g., "History", "Maths").
▪ notborrowed: Boolean flag indicating whether the book is available for
borrowing.
▪ borrowing_date: The date when the book was borrowed.
▪ returndate: The date when the book is due for return.
3. NotFound Class:
o Purpose: A custom exception thrown when a book is not found in the library.
o Key Methods:
▪ Constructor for the exception, which takes a message as a parameter.
4. gui Class:
o Purpose: Handles the graphical user interface for the library system.
o Key Methods:
▪ setupframe(): Sets up the initial window and components.
▪ updateOutput(String text): Updates the output area with text.
▪ setuplisteners(): Sets up event listeners for all buttons and inputs in the GUI.
▪ disableButtons(): Disables all action buttons in the GUI.
▪ enableButtons(): Enables all action buttons in the GUI.
▪ playSound(String soundFile): Plays the sound effect from the specified file
path.
o Attributes:
▪ frame: The main window of the GUI.
▪ panel: The main content panel of the GUI.
▪ panel2: A secondary panel holding the buttons.
▪ b1, b2, b3, etc.: Buttons for interacting with the library system (add, borrow,
return, etc.).
▪ label1, label2: Labels used for displaying text.
▪ tf1: TextField for user input (capacity, book ID, etc.).
▪ ta1: TextArea for displaying the output (e.g., list of books, borrowing info).
▪ sp: JScrollPane for the output area.
▪ lib: Instance of the library class representing the current library.
▪ combobox: JComboBox for selecting book categories.
▪ f: File object for saving library details.
5. main Class:
o Purpose: Entry point of the application. Initializes and runs the GUI.
o Key Methods:
▪ main(String[] args): Initializes the gui object and starts the application.
Key Features
1. Library Capacity: The user should set the maximum capacity of the library, and actions
like adding books are restricted based on this capacity.
2. Book Management: Users can add, borrow, return, and remove books from the library.
Each book has details like title, category, availability status, borrowing period, and return
date.
3. Search Functionality: Users can search for a book by its title.
4. Borrowing System: The system tracks whether a book is available for borrowing and
prevents users from borrowing a book that is already borrowed.
5. User Interface: A user-friendly graphical interface for interacting with the library system.
It includes buttons for all major actions (e.g., add book, borrow book, remove book, etc.).
6. Book Categories: Books can be categorized (e.g., "History", "Maths",
"Science","Biology", "Politics"), and the user selects a category when adding a book.
7. Search for Books: The user can search for a specific book by its title using the search
button. The search result will be displayed in the output area.
Exception Handling:
• Invalid Input: Users are alerted if invalid inputs (e.g., empty fields, non-numeric capacity,
etc.) are entered.
• Book Not Found: If a user tries to borrow, return, or remove a book that doesn't exist, a
custom NotFound exception is thrown.
• Library Full: If the library has reached its maximum capacity, the user is informed and
cannot add more books.
• Empty Library: If there are no books to borrow or return, an appropriate message is
shown.
• File Handling: If there is an issue saving or loading the library details, an error message
is shown.
This Library Management System provides an easy-to-use interface for managing books in a
library, making tasks such as adding, borrowing, returning, and removing books simple and
efficient. The use of Java Swing for the GUI ensures a user-friendly experience, and the backend
logic is designed to handle all basic library operations.
Simulation:
The following window appears when the code runs; all the buttons are disabled until the user enters
the capacity.
All of the following snapshots show what happens upon entering data or choosing a button.
Capacity is entered.
We also added a feature to know the function of each component in our system.
For example,