INFORMATION & COMPUTER SCIENCE DEPARTMENT, KFUPM
ICS102, SECTION 65 (002
Semester)
INTRODUCTION TO COMPUTING
Project Document
Instructor: Bashir M. Ghandi
This project is about developing a simple library
system 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 TestLibrary as described below:
1. Book class: This involves 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
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
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 the form : “ 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 |
2. Member Class: This 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)
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:
addBook: takes a number and increase numberOfBooks by it
removeBook: 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.
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 two arrays (instance
variables) by reading data from the files books.txt and members.txt
Methods to
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.
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
saveBooks: overwrites the file
books.txt with the content of the array books.
saveMembers: overwrites the file
members.txt with the content of the array members.
4. TestLibrary: This is an application
class.
It should
create a Library object and then repeatedly display the following menu and
allows a user to perform the various tasks until the Exit option is
selected.
Option 1: This should
read the details of a member from the user.
If the member is not already a member of the library (i.e. if it is not
already in the array members) it should be added in the next slot of the array
members. If a member with same ID
already exists, an error message should be displayed.
Option 2: This
should display the list of all members of the library:
Option 3: This should
read the details of a book from the user.
If the book is not already in the system, it should be added.
Option 4: This should display the list of all books in the
library.
Option 5: This should read the ID number of a member and the
book number and provided the following conditions are satisfied, the that book
should be borrowed to the member. The conditions are:
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.
Option 6: This should
read the ID number of a member and the book number abd provided the following
conditions are satisfied, the book should be returned. The conditions are:
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 currently borrowed
Option 7: This should
save the content of the arrays books and members in the corresponding data
files and
Important
Points :