0% found this document useful (0 votes)
3 views1 page

Java OOP Exercise

The document outlines a Java Object-Oriented Programming exercise to create a Library Management System. It specifies the creation of classes for Book, User, and Library with defined attributes and methods, as well as rules for borrowing and returning books. The expected output demonstrates the functionality of the system in managing book availability and user interactions.

Uploaded by

oteaching351
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Java OOP Exercise

The document outlines a Java Object-Oriented Programming exercise to create a Library Management System. It specifies the creation of classes for Book, User, and Library with defined attributes and methods, as well as rules for borrowing and returning books. The expected output demonstrates the functionality of the system in managing book availability and user interactions.

Uploaded by

oteaching351
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java OOP Exercise: Library Management System

Goal:
Build a mini system to manage a library with books and users using Object-Oriented Programming
concepts (no interfaces).

Requirements:
1 Create class Book with attributes: title, author, isAvailable
2 Methods: borrowBook(), returnBook(), toString()
3 Create class User with attributes: name, borrowedBooks (ArrayList)
4 Methods: borrow(Book), returnBook(Book), printBorrowedBooks()
5 Create class Library with attributes: books, users (ArrayList)
6 Methods: addBook(), addUser(), showAvailableBooks(), findBook(String title),
borrowBook(User, String), returnBook(User, String)

Rules:
1 A user cannot borrow a book if it is already borrowed
2 A user cannot return a book they do not have
3 Use encapsulation (private fields)
4 Use constructors properly

Expected Output When Running main():


1 Available books:
2 - Book A
3 - Book B
5 Ali borrows Book A
6 Available books now:
7 - Book B
9 Ali tries to borrow Book A again:
10 Error: Book is not available
12 Ali returns Book A
13 Available books now:
14 - Book A
15 - Book B

You might also like