0% found this document useful (0 votes)
2 views3 pages

Asmt 1.2

The document outlines the requirements for a Java console application to manage a library system, allowing users to add, display, search, and count books. It specifies the structure of the Book and Library classes, including their attributes and methods, as well as the main class for user interaction. Additionally, it includes non-functional requirements and an example run to illustrate user input and expected outputs.

Uploaded by

shyngysdatkabek
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)
2 views3 pages

Asmt 1.2

The document outlines the requirements for a Java console application to manage a library system, allowing users to add, display, search, and count books. It specifies the structure of the Book and Library classes, including their attributes and methods, as well as the main class for user interaction. Additionally, it includes non-functional requirements and an example run to illustrate user input and expected outputs.

Uploaded by

shyngysdatkabek
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
You are on page 1/ 3

Assignment: Library Book Management System

Objective
Create a Java console application to manage a library system, where users can:

1. Add books with their titles and authors.


2. Display all books in the library.
3. Search for a book by title.
4. Count how many books are in the library.

Functional Requirements
1. Book Class (Book)

Create a Book class that represents a book with:

 Instance Variables:
o String title – stores the book’s title.
o String author – stores the book’s author.
 Constructor:
o Book(String title, String author) – initializes the book’s title and author.
 Method:
o void display() – prints the book details in "Title by Author" format.

2. Library Class (Library)

Create a Library class to manage books.

2.1. Fields:

 Book[] books – an array to store multiple Book objects.


 int count – tracks the number of books added.

2.2. Constructor:

 Library(int size) – initializes the books array with a specified size.

2.3. Methods:

✅ void addBook(String title, String author):

 Adds a new Book object to the array.


 Ensures books cannot be added if the array is full.

✅ void displayBooks():

 Prints a list of all books using the display() method.


✅ void searchBook(String title):

 Searches for a book by title (case-insensitive).


 If found, prints "Book found: Title by Author".
 If not found, prints "Book not found".

✅ int countBooks():

 Returns the total number of books in the library.

3. Main Class (Main)


Implement the main method to handle user interaction using Scanner.

3.1. Steps in Main Method:

1. Ask the user:


o "Enter the number of books the library can hold:"
o Store the input as int numBooks.
2. Create an instance of Library with numBooks as the array size.
3. Use a menu-driven loop (while loop) to let users:
o Add a new book.
o Display all books.
o Search for a book.
o Count books in the library.
o Exit the program.

Non-Functional Requirements
 ✅ The program should handle incorrect inputs (e.g., empty titles, duplicates).
 ✅ Use loops for the menu and input collection.
 ✅ Use arrays to store books.
 ✅ Follow OOP principles (encapsulation, modularity).

Example Run (User Input in Bold)


txt
КопироватьРедактировать
Enter the number of books the library can hold: **5**

Menu:
1. Add Book
2. Display Books
3. Search for a Book
4. Count Books
5. Exit
Enter choice: **1**

Enter book title: **The Alchemist**


Enter author: **Paulo Coelho**
Book added successfully!

Enter choice: **1**


Enter book title: **1984**
Enter author: **George Orwell**
Book added successfully!
Enter choice: **2**
--- Library Books ---
The Alchemist by Paulo Coelho
1984 by George Orwell

Enter choice: **3**


Enter book title to search: **1984**
Book found: 1984 by George Orwell

Enter choice: **4**


Total books in the library: 2

Enter choice: **5**


Exiting the program...

You might also like