CS2312 Problem Solving and Programming

Library Application V.2
(Prepared by Mr. LIU Ho Yin)


Version 1 [2012, by Dr. Sam NG T H] - Application developed in C++
Version 2 [2014, by Mr. LIU Ho Yin] - Rewritten in Java

Overview of Library System Program

The Library System has the following functionality:

  1. Register a new member. A member may be a child, adult or senior.
  2. Cancel an existing member.
  3. Search for the details of an existing member.
  4. Add a new book.
  5. Remove the record of a book.
  6. Search for the details of a book.
  7. A member borrows a book.
  8. A member returns a book.
  9. A member pays fine. Fine rate is $3/day for children, $10/day for adult and $5/day for senior.
  10. Undo the last action performed by the user.


You can also download the image of UML from HERE

Guideline for the run of Library System Program in eclipse

1. Download the Jar file from HERE

2. Open Eclipse, create a new Java Project

3. Enter MyLibrarySystem as the project name, be aware of the project's location.

4. Copy the Jar to the project's folder, if you forget the project's location, you should check THIS out!!

5. Right click the project folder, choose "Configure Build Path"

6. Choose Libraries tab, click "Add External JARs"

7. Choose the Jar file under project's folder

8. You can see that LibrarySystem.jar will be added to the build path, click OK to proceed

9. After the configuration, there will be a Referenced Libraries, including the LibrarySystem.jar

10. You can expand the jar to see the contents, the jar file is just an archive file for holding the class files

11. Right click the project folder, choose "Run As", then choose "Run Configurations"

12. DOUBLE CLICK "Java Application", then click the "Search" button

13. Choose "Main" and click "OK"

14. Make sure you see the "Main" inside the field of Main class, then click the "Run" button

NOTE: After setting up the run configuration, you can just click the "Run" button on the toolbar to run the program next time

15. Enter 1 for console output mode. There are 3 output modes in this program.
1 for console output mode, the results are displayed on the console.
2 for output.txt, the results are printed on output.txt under project's folder.
3 for dual mode, the results are both displayed on the console and printed on the output.txt under project's folder.

16. Enter the command, register 001 sam senior, result will be shown on the screen
You can try your own or follow the sample rundown1, rundown2, rundown3

Check your project's location

Input format of commands

  • register id name [child | adult | senior]
  • unregister id
  • searchMember [id]
  • arrive callNo title authors
  • lose callNo
  • searchBook callNo
  • checkout id callNo duedate
  • checkin callNo returndate
  • pay id fine
  • undo

Note 1: Bold indicates fixed strings; all variables are string inputs; [ ] indicates optional
Note 2: id indicates a member id; name indicates the name of a member; callNo indicates an id of a book; title is the title of a book; authors is the author name;
duedate indicates the last day a member should return the book;
returndate indicates the day a member actually returns the book;
fine indicates the amount of money a member pays to settle fine payment.
The format of duedate and return date must be dd/mm/yyyy.

Sample rundown1 (Basic functions)

This rundown demonstrates some BASIC function in the library system such as
  • Register a new member
  • Search the members
  • Add a new book
  • Search the books
  • Checkout a book
  • Checkin (return) a book
  • A member pays fine

Sample rundown2 (More advanced functions)

This rundown demonstrates more ADVANCED functions in the library system such as
  • Search a member
  • Search a book
  • Unregister a member
  • Lose a book

Sample rundown3 (undo and some error testing)

This rundown mainly demonstrates the undo operation, it is a little bit complicated, so there are some explanations on the work flow.

Register a new member

  1. test wrong input format
  2. register 4 members
  3. undo the last registration, 3 members remain

Unregister a member

  1. test wrong input format
  2. unregister a member 003, 2 members remain
  3. undo unregister, 003 is added back, 3 members remain now

Add a new book

  1. test wrong input format
  2. add 4 new books
  3. undo the last process for adding B4, so 3 books remain

Lose a book

  1. test wrong input format
  2. we have added 3 books above
  3. lose a book B1, so only 2 books remain
  4. we find back B1, therefore, undo the process of losing book for B1
  5. B1 is added back, so 3 books remain

Check out a book

  1. test wrong input format
  2. a member:001 checkout a book:B1 at due date:15/02/2009
  3. a borrowing record can be shown on the personal record and the book record
  4. undo the checkout, the member:001 return the book:B1
  5. after the return, no borrowing record will be shown on either personal record or book record

Check in a book

  1. test wrong input format
  2. a member:001 checkout 2 books:B2 & B3 at due date:15/02/2009
  3. 2 borrowing records for B2 & B3 can be shown on the personal record
  4. member:001 checkin B2 at return date:18/02/2009, fine will be increased from 0 to 15, and the borrowing record for B2 will disappear
  5. undo the checkin, the borrowing record of B2 is added back, the fine will be restored to 0.

A member pays fine

  1. a member:001 checkin a book:B3 at return date:18/02/2009
  2. previously, we have borrowed B3 at due date:15/02/2009
  3. So 3 days is the difference between the return date and the due date
  4. Since 001 is a senior, $5 of fine per days. 5*3 = $15 will be added to his outstanding fine
  5. member:001 pay 10 dollars, 5 dollars remain
  6. undo the payment, 10 dollars are given back to member:001
  7. member:001 pay 15 dollars, so 0 remain