The Library System

Joel Goncalves

Computer Science (Bsc)

Abstract        A simple information system for the school library was designed, where records of books could be added, deleted or printed to the screen.  The classes Record and Library were created in order to represent the main purpose of the project, which was storing information regarding a particular book in a collection of book records allocated in the Library class.  From the Library class we can access these records, edit them, or get the data contained in them.  We can also get a list of all the records in the collection printed out to the screen.

1.  Introduction

The laboratory session was carried out with the use of a programming utility for Java named BlueJ.  The theory, and main objective, of java programming is the interaction between objects.  An object is regarded as an instance of a class, which can be seen as a set of instructions towards  the construction and interactivity of the object - its data and behaviour.  So while a class is responsible for characterising the objects, these are in charge of interacting with other objects (defined by other classes), if that is the programmer’s will.  

In this lab session only 2 classes were used, Library and Record. The programming environment in which this laboratory was produced can be witnessed in the figure below.  The objects are represented by the red rectangles in the bottom, while the two classes in use are above the objects, respectively named.  The arrow from Library to BookRecord shows that Library uses objects from the other one, which will be verified throughout the report.

Figure 1: The programming environment provided by BlueJ

2.  The BookRecord class

This class was designed to represent a record of a book.  Therefore, we should have attributes such as title, author name, publishing year and number of copies (which we call instance variables or fields).  We should have a way to access these fields, so accessor methods were created, in order to retrieve the values represented by these instance variables.  Of course, each class has to contain a constructor, with which an instance of that class is created.  So the first method we implemented was this constructor method, which would take values for each of the fields defined above (we call these values parameters passed onto the method), and create a book record.  The code for the constructor is as follows:

Join now!

    public BookRecord(String author, String title, int year, int copies)

    {  

        // Create a new book record, error check everything using exceptions

   

        try {

            // Check author is valid

            if(author == null || author.length() == 0) {

                throw new IOException("No author entered");

            } else {

                this.author = author;

  ...

This is a preview of the whole essay