You are on page 1of 4

Object-Oriented Language and Theory

Lab 4: Message Sending and Object Usage


Lab’s Objectives:
In this lab, you will practice with:
▪ Write constructors for classes, create objects from classes, send message to objects,
▪ Different types of parameter passing,
▪ Create classifier members (i.e. static in Java) and compare to instance members
▪ Method overloadings

In this lab, you continue using Eclipse or NetBean to develop a simple program for managing books in small
library. This program is console-application.

There are 3 classes:


▪ The Program class provides a main() method which interacts with the rest of the system
▪ The Book class which stores information of a book in library
▪ The Library class to maintain an array of book objects, illustration of “books in the library”
Note: You can design your own program for solving the problem
1. Open Eclipse or Netbean
2. Create new Java Project

3. Create Book class which stores information of a book in library

+ UML diagram for Book class: (note “-”: private and “+”: public)

1
+ Add getter/setter methods for private variables
+ Method overloading allows different methods to have same name but different signatures where
signature can differ by number of input parameters or type of input parametere or both. Overloading
constructor of Book class:
- A constructor with no parameter, setting default values for book object’s attributes
- A constructor with full parameters.
+ Write method showBookInfo() to display book’s information in console, formatting the outline as
below:
Book Title: …
Book ID: …
Total Amount: …
Available: …
4. Create Library class
+ UML diagram for Library class: (note “-”: private and “+”: public, underlining: static variable or
static method, constant: CAPITALIZATION)

+ This class maintains an array of book objects, illustration of books in the library.
+ Add a variable named "libraryTitle" to store the title of library.
+ We suppose that, small library only contains a limited number of books. That means: if the current
number of books is over this limited number, users cannot add new book in library.
- Create a class variable named "nbBooks" current number of books in library, each time an
instance of the Book class is added to the library, the nbBooks should be updated.
- Create a constant for limited number of books in library.
2
- Add getter/setter methods for private variables
+ Write constructors for Library class.
+ Method addNewBook(): Add new book

Before creating a new Book object, you should check if the current number of books is below the
MAX_NUMBER_BOOKS.
+ Method findBook(bookID)
Available:
Retuns true, Print out Title, number of books left
Otherwise:
Return false

+ Method borrowBook(bookID)
Check if the book is available or not
If available then borrow, and update the number of books left
Show again the updated status

+ Method returnBook(bookID)
Update the number books left
Show again the updated status

3
+ Write method showLibraryInfo() to display library’s information in console
5. Create Program class
+ UML diagram for Program class: (note “-”: private and “+”: public)

+ This class provides a main() method.


- In the main function of the class Program:
o Call method showMenu()

o Process user’s option and display the result.


6. Change Library class
+ Add Method findBook(keyword)
- Find books by keyword in the book title
Submission:
◼ Due: 24h 03/03/2019
◼ Compress your source files into a ZIP file
◼ Name the zip file according with the following template:
❑ OOLT20182_StudentID_lab4.zip
◼ Example: OOLT20182_20091004_lab4.zip
◼ Submit the file to lecturer
❑ Email address: tuannm@soict.hust.edu.vn
❑ Subject: “OOLT20182_StudentID _lab4”
◼ Example: OOLT20182_20091004_lab4

You might also like