INFORMATION & COMPUTER SCIENCE DEPARTMENT, KFUPM

ICS201, SECTION 52  (002 Semester)

INTRODUCTION TO COMPUTER SCIENCE

Project Document

 

Instructor: Bashir M. Ghandi

 


This project is about developing an interactive GUI application for library management for a certain Computer club, which has a few computer books that its members can borrow.

 

The data for the system is stored in two text files: books.txt and members.txt.

books.txt has five columns separated by the ‘#’ character, and representing the following:

bookNumber:  each book has a unique identification number

author: name of the book author

title: title of the book

borrowed: the status of the book (0 for available and 1 for borrowed)

borrower: If the book is borrowed, this should contain the ID number of the member who borrowed the book, else, it should be empty.

990001#Ahmad Muhammad#Programming Languages#0#none

990002#Usman Mohammed#Java made Easy#1#6990239

990003#Usman Yahaya#History of Computing#0#none

 

members.txt has three columns separated by ‘#’ character, and representing the following:

iDNumber: each club member has a unique identification number

name: name of the member

numberOfBooks: the number of books borrowed by the member

6990239#Khalid Hassam#1

9565247#Yakub Umar#0

 

You are to write four java classes, namely; Book, Member, Library and LibrarySystem as described below:

1.   Book class:  This should implements the Comparable interface and should have at least the following fields, constructors and methods:

Fields:

bookNumber of type String

author of type String

title of type String

borrowed of type boolean

borrower of type String

 

Two constructors to:     

initialize a Book object given all the instance variables

initialize a Book object given only bookNumber, author and title (borrowed = false, borrower = “none”)

Methods to:

getBookNumber

isBorrowed : returns true if the book is borrowed

getBorrower

setBorrowed

setBorrower

borrowBook : receives ID number and assigns it to borrower field and change the borrowed field to true

returnBook :change borrower field to “none” and borrowed to false

toString : returns the book as a string in a form suitable for display on the screen :

           “ booNumber  Author   Title  Available/Borrowed”

toString2: returns the book as a string in a form suitable for printing to the books.txt file:

990001#Ahmad Muhammad#Programming Languages#0#none  

equals()

compareTo()

 

  1. Member Class:  This should also implements the Comparable interface and should have at least the following fields, constructors and methods

Fields

iDNumber of type String

name of type String

numberOfBooks of type int (number of books borrowed by a member)

Two constructors to

initialize a Member object given all the instance variables

initialize a Member object given only iDNumber and name (numberOfBooks = 0)

 

Methods to

getIDNumber

getName

getNumberOfBooks:

addBooks:  takes a number and increase numberOfBooks by it

removeBooks: takes a number and reduce numberOfBooks by it

toString: returns the member object as a string in the form: “iDNumber  name  numberOfBooks”

toString2: returns the member object as a string in a form suitable for printing in the file, members.txt.

equals()

compareTo()

 

3.   Library class: This should have at least the following fields, constructors and methods

Fields

books : an array of Book objects   //assume a maximum of 20 books

members: an array of Member objects // assume a maximum of 20 members

numberOfBooks : actual number of books in the library

numberOfMembers: actual number of members of the club

Constructors to:

initialize the instance variables by reading data from two data files passed to it as String parameters.

Methods to

getBooks

getMembers

getNumberOfBooks

getNumberOfMembers

getBook : returns a book object given its index

getMember: returns a member given its index

isBorrowed : returns true if a book at a given index is borrowed, false otherwise

addBook: adds a given Book object at the next free slot in the books array

addMember: add a given Member object at the next free slot in the members array

findBook: returns the index of a book, given an a book number, -1 if the book does not exists.

findBook: returns the index of a book, given a book object, -1 if the book does not exists.

findMember: returns the index a member, given an ID number, -1 if the member does not exists

findMember: returns the index of a member, given a Member object, -1 if the member does not exists.

removeMember: removes member from the array and shift the rest of the members to occupy the slot left.

borrowBook: receives a Book object and a Member object as parameters, find the location of the Book object from the books array and calls its borrowBook method giving it the ID number of the Member object as argument

Also find the location of the Member object from the array members and increase its numberOfBooks by 1.

returnBook: reverse of borrowBook

listBooks: prints all the books on the screen

ListMembers: prints all the members on the screen

saveData: overwrites the content of data files received as parameters with the content of the two arrays.

 

  1. LibrarySystem: This should create an object of the Library class and then provide a Swing graphical user interface similar to (but not necessarily the same as the following) to manage the library.

 

 

 

Books Menu:  This has four options as shown above and they should function as follows: 

 

Add new Book: This should display a dialog window similar to the one on the right of the following table and allows the user to add new book to the library.    The system should make sure that the ID number of the new book is not the same as that of any of the existing books, else, the message on the right of the table should be displayed.

 

The remaining three options should display all books, available books and borrowed books in a window similar to the following.  In each of these options the list must be sorted by book number before the display.

 

 

Members Menu: This should allow options for adding a new member to the library, removing a member and displaying all members.

 

Adding a new member and removing an old member should display dialog windows similar to the following:

 

Again the system should not allow two members to have the same ID number.  If the user enters an ID number that already exists, an appropriate error message should be displayed in a window.

 

The display of all members is similar to display of all books.  The list should be sorted by ID number.

 

Lone Menu: This allows for loaning and returning a book.  These should display the following windows respectively:

 

Loan should be allowed to take place only if all of the following conditions are satisfied, else an appropriate error message should be displayed.

1.       The ID number is for a valid member

2.       The book number is for a valid book (the book exists)

3.       The book is not already borrowed

4.       The member has not borrowed up to two books already.

 

Similarly, returning of a book should be allowed only if both of the following conditions are true.

1.       The book number is for a valid book (the book exists)

2.       The book is currently borrowed

 

Finally, when the user attempts to close the program, the system should allow the user to save changes by displaying the following window.

 

 

Important Points :