CSOO 122 – Object Oriented Programming
Spring 2025
Assignment - 3
Name:
Roll No
Issue Date: May 3, 2025, 2025
Task No 1
Library User System (Interfaces + Business Logic)
You are to build a mini Library User System that demonstrates the use of interfaces, method
overriding, and basic business rules using OOP concepts in Java.
Requirements:
1. Define the LibraryUser Interface
Include the following:
• A constant MAX_BOOKS_ALLOWED = 3
• Abstract methods:
o void registerAccount(int age)
o void requestBook(String bookType, String bookName)
o boolean canBorrowMoreBooks() — returns true if under the borrowing limit.
o void returnBook(String bookName) — simulates returning a borrowed book.
o void viewBorrowedBooks() — prints all currently borrowed books.
2. Create Two Implementing Classes: KidUser and AdultUser
Both classes must:
• Track:
o Age of the user
o List of currently borrowed books (use ArrayList<String>)
• Enforce rules:
o Kids (age < 12) can register
o Adults (age ≥ 12) can register
o Kids can request only Kids books
o Adults can request only Fiction books
o Limit the number of borrowed books to MAX_BOOKS_ALLOWED
• Display user-friendly messages upon:
o Registration success/failure
o Book request success/failure
o Attempt to borrow beyond the allowed limit
3. Create the LibrarySystem Driver Class
In the main() method:
• Create and register at least one KidUser and one AdultUser
• Demonstrate:
o Valid and invalid registration
o Book requests within and beyond limit
o Attempting to request a book of the wrong category
o Viewing and returning books
National University of Modern languages
Page 1 of 2
CSOO 122 – Object Oriented Programming
Spring 2025
Assignment - 3
Name:
Roll No
Issue Date: May 3, 2025, 2025
OUTPUT
Sample Behaviors to Implement:
✔ KidUser (age 10) registers successfully
✔ KidUser requests “Diary of a Wimpy Kid” (Kids book) → Success
✖ KidUser requests “The Da Vinci Code” (Fiction book) → Failure
✖ KidUser tries to borrow 4 books → Denied
✔ AdultUser (age 18) registers successfully
✔ AdultUser requests “The Great Gatsby” (Fiction book) → Success
✔ AdultUser returns a book → Updated borrow list
Task No 2:
1. Define exception handling in Java. Why is it important in object-oriented programming?
2. Differentiate between checked and unchecked exceptions with at least two examples of each.
3. Explain the purpose of the following exception-handling keywords with example usage:
•
try
•
catch
•
throw
•
throws
•
finally
Task No 3:
1. Explain how generics are used with collections. Why is it important to use generics with
collections?
2. What are Java Collections? Explain how they are better than arrays in managing data.
3. Describe the difference between the following collection types:
• ArrayList vs LinkedList
• HashSet vs TreeSet
• HashMap vs TreeMap
National University of Modern languages
Page 2 of 2