a real-world example question that can be solved using Java basics:
You are tasked with developing a simple program to manage books in a small library. The library needs to keep track of its books, allowing the librarian to perform the following actions:
- Add a new book to the collection.
- Display the details of all books in the collection.
- Search for a book by its title.
Each book has the following attributes:
Title
Author
ISBN
(International Standard Book Number)Published Year
-
Add a Book:
- Prompt the user to enter the details of a new book.
- Store the book in a list.
-
Display Books:
- Display the details of all books in the collection.
-
Search a Book:
- Prompt the user to enter the title of the book they want to search for.
- Display the details of the book if found; otherwise, display a message saying the book is not found.
- Use only basic Java constructs: classes, methods, arrays (or ArrayList), loops, and basic input/output.
Enter 1 to add a book, 2 to display all books, 3 to search for a book, 4 to exit: 1
Enter Title: Java Programming
Enter Author: John Doe
Enter ISBN: 1234567890
Enter Published Year: 2020
Enter 1 to add a book, 2 to display all books, 3 to search for a book, 4 to exit: 2
Title: Java Programming, Author: John Doe, ISBN: 1234567890, Published Year: 2020
Enter 1 to add a book, 2 to display all books, 3 to search for a book, 4 to exit: 3
Enter Title to search: Java Programming
Title: Java Programming, Author: John Doe, ISBN: 1234567890, Published Year: 2020
Enter 1 to add a book, 2 to display all books, 3 to search for a book, 4 to exit: 4
Goodbye!
This example uses basic Java constructs to solve a practical problem, making it an excellent exercise for those learning Java basics.
SELF TRY