You are on page 1of 64

BOOK MANAGERMENT SYSTEM

PROGRAM TITLE: PROGRAMMING


UNIT TITLE:
ASSIGNMENT NUMBER:
ASSIGNMENT NAME: BOOK MANAGERMENT SYSTEM.
SUBMISSION DATE:
DATE RECEIVED:
TUTORIAL LECTURER: LƯƠNG THỊ THẢO HIẾU
WORD COUNT:

STUDENT NAME: LÊ PHÚ BÌNH

STUDENT ID: BKC90072

MOBILE NUMBER: (+84) 925800825

LE PHU BINH 1
BOOK MANAGERMENT SYSTEM

Summative Feedback:

Internal verification:

LE PHU BINH 2
BOOK MANAGERMENT SYSTEM

Student Name /ID Number Lê Phú Bình / BKC90072

Unit Number and Title Unit 01: PROGRAMMING

Academic Year

Unit Assessor

Assignment Title BOOK MANAGERMENT SYSTEM

Issue Date

Submission Date

IV Name

Date

Submission Format

Each student must submit their assignment as guided in the assignment brief. The students are guided on
what sort of information is to produce to meet the criteria targeted. Some tasks might require group work,
but the student must produce the individual assignment.

Unit Learning Outcomes

LO1. Define basic algorithms to carry out an operation and outline the process of programming an
application.

LO2. Explain the characteristics of procedural, object-orientated, and event-driven programming.

LO3. Implement basic algorithms in code using an IDE.

LO4. Determine the debugging process and explain the importance of a coding standard.

Assignment Brief and Guidance

You have been recently recruited as a junior application designer in one of the top IT companies in
Vietnam. iBook hired the company to create a program for the books management system. Each book has
an id, name, author, language, price, publish date, and ISBN.

The system should have at least two main menus which are:

I. Books

a. insert a new book b. update a book


c. delete a book d. display all

II. Tools

LE PHU BINH 3
BOOK MANAGERMENT SYSTEM

a. filter by author b. filter by language


c. filter by price d. order by price desc

Based on the context above, complete the following.

Part 1:
You have been tasked with creating a presentation on algorithms and their benefit to software
development.

As the results will need to be delivered to your peers, consider this as a mini-research project that will be
presented.

You will need to explain what an algorithm is, with examples of their use, comparing their efficiency
against brute-forcing, and how it will relate to the application development process, down to the
implementation in a suitable language. The presentation will be most effective if it includes an example
and concludes with an evaluation of the implementation of the algorithm.

Your research should be conducted on a choice of algorithms, including sorting, and searching data
and/or encryption/decryption, compression/decompression.

Note: The submission is in the form of a ten-minute Microsoft® PowerPoint® style presentation, you
should be prepared to present to your colleagues before presenting to the customer. The presentation can
include links to performance data with additional speaker notes. The presentation slides will need to be
submitted with speaker notes. You are required to make effective use of headings, bullet points, and
subsections as appropriate. Your research must be referenced using the Harvard referencing system. The
recommended word limit is 500 words, including speaker notes, although you will not be penalized for
exceeding the total word limit.

Part 2:
The research and development team you work with has been tasked with further investigation into how
best to build more efficient, secure software. You have been asked to investigate programming paradigms
and the advantages and disadvantages of using different programming language approaches.

You will need to create a report covering findings from research into the characteristics of different
programming paradigms – procedural, object-orientated, and event-driven programming.

Your report should include an explanation of each paradigm, an analysis of suitable IDEs, and an
evaluation of source code that would be generated for an application.

Note: The submission is in the form of an individual written report. This should be written in a concise,
formal business style using single spacing and font size 12. You are required to make use of headings,
paragraphs, and subsections as appropriate, and all work must be supported with research and referenced
using the Harvard referencing system. Please also provide a bibliography using the Harvard referencing
system. The recommended word limit is 2,000–2,500 words, although you will not be penalized for
exceeding the total word limit.

Part 3:

You have been asked by your manager to develop a working application following your design and

LE PHU BINH 4
BOOK MANAGERMENT SYSTEM

program specifications of the management system.

The submission is in the form of five documents/files:

1. Stage 1 – Development Document


2. Stage 2 – Report (IDE Evaluation)
3. Stage 3 – Report (Debugging Evaluation)
4. Stage 4 – Report (Evaluation Report) including fully commented source code
5. An installable and executable version of your application

You are required to make use of appropriate structure, including headings, paragraphs, subsections, and
illustrations as appropriate, and all work must be supported with research and referenced using the
Harvard referencing system.

The document portfolio should include:

1. Evidence of how the IDE was used to manage the development of your code.
2. An evaluation of developing applications using an IDE versus developing an application without using
an IDE.
3. An evaluation of the debugging process in the IDE used and how it helped with development.
4. An evaluation of coding standards and the benefits to organizations of using them.

The working application produced must also be demonstrated.

CATALOG
PRODUCTION..............................................................................................................................................................................6
LO1. Define basic algorithms to carry out an operation and outline the process of programming an application.............6
1.Algorithm......................................................................................................................................................................................6
2. Steps to development a program.................................................................................................................................................9
3. Write a program.........................................................................................................................................................................12
LO2. Explain the characteristics of procedural, object-oriented, and event-driven programming....................................13
1. Procedure oriented programming..............................................................................................................................................13
2. Object-orientated programming................................................................................................................................................16
3. Differences between Procedural and Object Oriented Programming.......................................................................................23
4. Event-drive programming..........................................................................................................................................................25
5. The Relationship between Procedure, Object Oriented and Event Driven Programming........................................................33
LO3. Implement basic algorithms in code using an IDE.........................................................................................................34
1. General introduction..................................................................................................................................................................34
2. System Requirements................................................................................................................................................................35
3. Diagram.....................................................................................................................................................................................35
4. Code...........................................................................................................................................................................................37
5. Test............................................................................................................................................................................................47
LO4. Determine the debugging process and explain the importance of a coding standard.................................................55
1. Debugging.................................................................................................................................................................................55
2. The importance of a coding standard........................................................................................................................................61
Referance......................................................................................................................................................................................63

LE PHU BINH 5
BOOK MANAGERMENT SYSTEM

PRODUCTION
Programming is one of the subjects in which students must master the knowledge base, including
understanding programming models such as procedural programming, objectoriented programming, and
event-oriented programming, the structure of a program, data, and basic data, while also learning about
the IDE, its functions, and some standard rules, such as naming in code. At the same time, it assists
students in learning how to create simple apps.

LO1. Define basic algorithms to carry out an operation and


outline the process of programming an application.

1.Algorithm

1.1 Overview algorithm


• Definition: An algorithm is a procedure or formula used for solving a problem. It contains the steps,
which is a set of actions that are executed in a certain order to obtain the desired output.

For example: The brew tea algorithm

• Characteristics of algorithm:

 Input: An algorithm requires some input values. An algorithm can be given a value other than 0 as
input.

 Output: At the end of an algorithm, you will have one or more outcomes.

LE PHU BINH 6
BOOK MANAGERMENT SYSTEM

 Unambiguity: A perfect algorithm is defined as unambiguous, which means that its instructions
should be clear and straightforward.

 Finiteness: An algorithm must be finite. Finiteness in this context means that the algorithm should
have a limited number of instructions, i.e., the instructions should be countable.

 Effectiveness: Because each instruction in an algorithm affects the overall process, it should be
adequate.

 Language independence: An algorithm must be language-independent, which means that its


instructions can be implemented in any language and produce the same results.

• Types of algorithm:

LE PHU BINH 7
BOOK MANAGERMENT SYSTEM

1.2 Flowchart

• Explain by pseudo code:

Step 1: START

Step 2: DECLARE tempName, tempGrade, i, j;

Step 3: SET i=0;

Step 4: WHILE i<total-1 is True,REPEAT step 5 through step 9

Step 5 SET j=i+1;

Step 6:WHILE j<total is True,REPEAT step 7 through step 8

Step 7: IF grade[I]>grade[j];

Step 7.1: SET tempName= name[i], SET tempGrade=grade[i].

Step 7.2: SET name[i]=name[j], grade[i]=grade[j].

Step 7.3: SET name[j]=tempName, grade[j]=teampGrade.

Step 8: INCREASE j by 1.

Step 9: INCREASE I by 1.

Step 10: STOP.

LE PHU BINH 8
BOOK MANAGERMENT SYSTEM

2. Steps to development a program

When we want to develop a program by using any programming language, we have to follow a sequence
of steps. These steps are called phases in program development.

The program development life cycle is a set of steps or phases which are used to develop a program in
any programming language.

1-Gathering & Analysis of Requirement:

Before the team of software technicians can cough up the general idea for any software, it is essential for
the team to gather the business requirements in this very first phase. At this point, the prime focus of the
stakeholders and project managers is to note the exact things needed from any software under
consideration. There are several questions to be asked at this stage, which include:

Who is supposed to use this software?

How will the software be used upon completion?

LE PHU BINH 9
BOOK MANAGERMENT SYSTEM

What type of data should be added to the software?

What should be the data output by this software?

Once these general questions are answered, a general outline is created for the software developers to
focus on. This data is then analyzed to ensure its validity & any possibility for incorporation of the same.
Lastly, a document for requirement specification is prepared which serves as a guideline for the next level
of the software development process.

2-Design:

This is the next phase for the software development process. In this stage, the draft design is prepared for
the software from the stage-1 requirement specifications. The system designs help in specifying the
hardware as well as system requirements. It also helps with the definition of an overall system in software
architecture.

The design specifications for the system serve as the input for the following phase of the software
development model. In this particular phase, test strategies are developed by the testers by mentioning
things to test and the ways to check it.

3-Coding/Implementation:

After receiving the design documents for the software to be created, the work following the design stage
is divided equally into various units and modules. This is the stage where actual coding begins. The main
focus of the phase is the development of perfect codes by the developers. This particular phase is the
longest in the entire protocol.

4-Testing:

LE PHU BINH 10
BOOK MANAGERMENT SYSTEM

5-

If you want to know what is software development; you can never skip understanding the testing stage.
This particular stage is very crucial for the developers. If anything goes wrong in the testing stage or any
error is noted in the codes, it can lead to the repetition of the coding process, and the cycle goes on till the
completion of the same. In this stage, all variants of the functional testing such as integration testing, unit
testing, system testing, acceptance testing, and non-functional testing are done.

5-Deployment Stage:

After all the errors from coding are removed during the testing stage, the next step is termed as the
deployment stage. The finalized code is implemented into the software and then deployed or delivered to
the customers to be used.

As the product is being given to potential customers, the first thing done to ensure that it works fine on a
large scale is to go with beta testing. If there is any possibility for changes or there are possible bugs
caught during implementation, it is immediately reported to the team that engineers its errors to work fine
in real-time. Once the changes are implemented with all the bugs fixed, the final dispersal or deployment
is set in motion.

6-Maintenance:

Once the customers start using well-developed software, the actual issues start surfacing with time. This
doesn’t mean that the software will get corrupted. However, it might require occasional issues surfacing
time and again. This particular process is termed as maintenance for the finalized product or software.

LE PHU BINH 11
BOOK MANAGERMENT SYSTEM

3. Write a program

LE PHU BINH 12
BOOK MANAGERMENT SYSTEM

LO2. Explain the characteristics of procedural, object-oriented,


and event-driven programming.

1. Procedure oriented programming

1.1 Definition
It is defined as a programming language derived from the structure programming and based on calling
procedures. The procedures are the functions, routines, or subroutines that consist of the computational
steps required to be carried. It follows a step-by-step approach in order to break down a task into a set of
variables and routines via a sequence of instructions.

During the program's execution, a procedure can be called at any point, either by other procedures or by
itself. The examples of procedural programming are ALGOL, COBOL, BASIC, PASCAL, FORTRAN,
and C.

1.2 Characteristics of procedure-orientated programming:


1. It emphasis on algorithm (doing this ).

2. Large programs are divided into smaller programs known as functions.

3. Function can communicate by global variable.

4. Data move freely from one function to another function.

5. Functions change the value of data at any time from any place. (Functions transform data from
one form to another.)

6. It uses top-down programming approach.

LE PHU BINH 13
BOOK MANAGERMENT SYSTEM

Advantages and Disadvantages of Procedural Programming

Advantages Disadvantages

 Procedural Programming is excellent for  The program code is harder to write


general-purpose programming Procedural Programming is employed

 The coded simplicity along with ease of  The Procedural code is often not reusable,
implementation of compilers and interpreters may pose the need to recreate the cod
needed to use in another application
 A large variety of books and online course
material available on tested algorithms, making  Difficult to relate with real-world objects
it easier to learn along the way
 The importance is given to the operation
 The source code is portable, therefore, it can be than the data, which might pose issues in
used to target a different CPU as well data-sensitive cases

 The code can be reused in different parts of the  The data is exposed to the whole pr
program, without the need to copy it making it not so much security friendly

 Through Procedural Programming technique,  There are different types of progra


the memory requirement also slashes paradigm as we mentioned before, whi
nothing but a style of programming.
 The program flow can be tracked easily important to understand that the paradigm
 not cater to a specific language but to the w
program is written. Below is a com
between Procedural Programming and
Oriented Programming.

Example for procerdure :

LE PHU BINH 14
BOOK MANAGERMENT SYSTEM

LE PHU BINH 15
BOOK MANAGERMENT SYSTEM

2. Object-orientated programming(OOP)

2.1 Definition
Object-oriented programming is a computer programming design philosophy or methodology that
organizes/ models software design around data or objects rather than functions and logic. It includes two
words, "object" and "oriented". In a dictionary object is an article or entity that exists in the real world.
The meaning of oriented is interested in a particular kind of thing or entity. In layman's terms, it is a
programming pattern that rounds around an object or entity.

The programming paradigm where everything is represented as an object is known as a truly object-
oriented programming language. Smalltalk is said to be the first truly object-oriented programming
language.

LE PHU BINH 16
BOOK MANAGERMENT SYSTEM

OOP is said to be the most popular programming model among developers. It is well suited for programs
that are large, complex, and actively updated or maintained. It makes the development and maintenance
of software easy by providing major concepts such as abstraction, inheritance, polymorphism, and
encapsulation. These four are also the four pillars of an object-oriented programming system.

OOPs, provide the ability to simulate real-world events much more effectively. We can provide the
solution to real-world problems if we are using the Object-Oriented Programming language. OOPs,
provide data hiding, whereas, in Procedure-oriented programming language, global data can be accessed
from anywhere.

The examples of OOPs are - C#, Python, C++, Java, PHP, Scala, Perl, etc.

2.2 Characteristics of Object-oriented programming

1. Objects

Object is a basic unit of Object Oriented Programming and represents the real life entities. A typical Java
program creates many objects, which as you know, interact by invoking methods. An object consists of: 

State : It is represented by attributes of an object. It also reflects the properties of an object.

Behavior : It is represented by methods of an object. It also reflects the response of an object with other
objects.

LE PHU BINH 17
BOOK MANAGERMENT SYSTEM

Identity : It gives a unique name to an object and enables one object to interact with other objects.

2. Class

A class is a user defined blueprint or prototype from which objects are created. It represents the set of
properties or methods that are common to all objects of one type. In general, class declarations can
include these components, in order: 

Modifiers: A class can be public or has default access (Refer this for details).

Class name: The name should begin with a initial letter (capitalized by convention).

When class is defined, objects are created as:

<classname><objectname>;

 If employee has been defined as a class, then the statement

employee manager;

will create an object manager belonging to the class employee.  

Superclass(if any): The name of the class’s parent (superclass), if any, preceded by the keyword extends.
A class can only extend (subclass) one parent.

Interfaces(if any): A comma-separated list of interfaces implemented by the class, if any, preceded by the
keyword implements. A class can implement more than one interface.

Body: The class body surrounded by braces, { }.

3.Inheritance

Inheritance is the mechanism by which one class can inherit the properties of another. It allows a
hierarchy of classes to be build, moving from the most general to the most specific. When one class is
inherited by another, the class that is inherited is called the base class. The inheriting class is called the
derived class. In general, the process of inheritance begins with the definition of a base class. The base
class defines all qualities that will be common to any derived class. . In OOPs, the concept of inheritance
provides the idea of reusability. In essence, the base class represent the most general description of a set
of traits. The derived class inherits those general traits and adds properties that are specific to that class.

LE PHU BINH 18
BOOK MANAGERMENT SYSTEM

4.Polymorphism

Polymorphism comes from the Greek words “poly” and “morphism”. “poly” means many and
“morphism” means form i.e.. many forms. Polymorphism means the ability to take more than one form.
For example, an operation have different behavior in different instances. The behavior depends upon the
type of the data used in the operation.

Different ways to achieving polymorphism in C++ program:

1) Function overloading

2) Operator overloading 

It is able to express the operation of addition by a single operater say ‘+’. When this is possible you use
the expression x + y to denote the sum of x and y, for many different types of x and y; integers , float and
complex no. You can even define the + operation for two strings to mean the concatenation of the strings.

LE PHU BINH 19
BOOK MANAGERMENT SYSTEM

5.Abstraction

Abstraction refers to the act of representing essential features without including the back ground details
or explanation. Classes use the concept of abstraction and are defined as a list of attributes such as size,
weight, cost and functions to operate on these attributes. They encapsulate all essential properties of the
object that are to be created. The attributes are called as data members as they hold data and the functions
which operate on these data are called as member functions.

Class use the concept of data abstraction so they are called abstract data type (ADT).

6.Encapsulation

Wrapping of data and functions together as a single unit is known as encapsulation. By default data is not
accessible to outside world and they are only accessible through the functions which are wrapped in a
class. Prevention of data from direct access by the program is called data hiding or information hiding.

LE PHU BINH 20
BOOK MANAGERMENT SYSTEM

Advantages Disadvantages

 Due to modularity and encapsulation, OOP  Object-Oriented programs tend to be slower


offers ease of management and use up a high amount of memory

 OOP mimics the real world, making it  Over-generalization


easier to understand
 Programs built using this paradigm may
 Since objects are whole within themselves, take longer to be created
they are reusable in other programs

Example for OOP:

Class TestStudent

Class Student

LE PHU BINH 21
BOOK MANAGERMENT SYSTEM

LE PHU BINH 22
BOOK MANAGERMENT SYSTEM

3. Differences between Procedural and Object Oriented


Programming
Object-oriented programming and procedural programming both are used to develop the applications. Both of them are high-level
programming languages. These two are important concepts, and it is also important to know the difference between them.

S.no. On the basis Procedural Programming Object-oriented programming


of

1. Definition It is a programming language that is derived from structure Object-oriented programming is a computer
programming and based upon the concept of calling programming design philosophy or
procedures. It follows a step-by-step approach in order to methodology that organizes/ models software
break down a task into a set of variables and routines via a design around data or objects rather than
sequence of instructions. functions and logic.

2. Security It is less secure than OOPs. Data hiding is possible in object-oriented


programming due to abstraction. So, it is more
secure than procedural programming.

3. Approach It follows a top-down approach. It follows a bottom-up approach.

LE PHU BINH 23
BOOK MANAGERMENT SYSTEM

4. Data In procedural programming, data moves freely within the In OOP, objects can move and communicate
movement system from one function to another. with each other via member functions.

5. Orientation It is structure/procedure-oriented. It is object-oriented.

6. Access There are no access modifiers in procedural programming. The access modifiers in OOP are named as
modifiers private, public, and protected.

7. Inheritance Procedural programming does not have the concept of There is a feature of inheritance in object-
inheritance. oriented programming.

8. Code There is no code reusability present in procedural It offers code reusability by using the feature of
reusability programming. inheritance.

9. Overloading Overloading is not possible in procedural programming. In OOP, there is a concept of function
overloading and operator overloading.

10. Importance It gives importance to functions over data. It gives importance to data over functions.

11. Virtual class In procedural programming, there are no virtual classes. In OOP, there is an appearance of virtual
classes in inheritance.

12. Complex It is not appropriate for complex problems. It is appropriate for complex problems.
problems

13. Data hiding There is not any proper way for data hiding. There is a possibility of data hiding.

14. Program In Procedural programming, a program is divided into small In OOP, a program is divided into small parts
division programs that are referred to as functions. that are referred to as objects.

15. Examples Examples of Procedural programming include C, Fortran, Pascal, The examples of object-oriented programming
and VB. are -
.NET, C#, Python, Java, VB.NET, and C++.

4. Event-drive programming

1. Define
Have you ever clicked a link on a web page or a button in an application and nothing happens? It can be
very frustrating when a component doesn't perform as expected. When we develop applications in any
language, it's important that user interaction actually does something.

Whenever you take action on a component, an event occurs. Whether anything happens after that event is
up to you, the programmer, to determine. If you have actions defined for these events, then you have
created an event-driven program or application.

LE PHU BINH 24
BOOK MANAGERMENT SYSTEM

2. Event
An event can be defined as a type of signal to the program that something has happened.

The event is generated by

External user actions

e.g. mouse movements, mouse clicks, and keystrokes

the operating system

eg. a Timer

2.1 Event Object


Everything in Java is object-oriented. It stands to reason then, that even events are tied to objects.
Basically, the event itself is an object; thus, we refer to this general concept as the event object.

To identify the source object of the event:

 use the getSource() instance method in the EventObject class.

 A component on which an event is generated is called the source object.

 All the event classes are subclasses of EventObject.

 If a component can generate an event, any subclass of the component can generate the same type of
event.

The subclasses of EventObject deal with special types of events, such as button actions, window events,
component events, mouse movements, and keystrokes.

LE PHU BINH 25
BOOK MANAGERMENT SYSTEM

Every GUI component can generate MouseEvent, KeyEvent, FocusEvent, and ComponentEvent.

2.2 The delegation model

 A listener may listen for multiple sources.

 The listener objectʹs class must implement the corresponding event-listener interface.

 The listener object must be registered by the source object.

 A source may have multiple listeners.

 Each event class has a corresponding listener interface.

LE PHU BINH 26
BOOK MANAGERMENT SYSTEM

The subclasses of EventObject deal with special types of events, such as button actions, window events,
component events, mouse movements, and keystrokes.

Every GUI component can generate MouseEvent, KeyEvent, FocusEvent, and ComponentEvent.

 A listener may listen for multiple sources.

 The listener objectʹs class must implement the corresponding event-listener interface.

 The listener object must be registered by the source object.

 A source may have multiple listeners.

 Each event class has a corresponding listener interface.

LE PHU BINH 27
BOOK MANAGERMENT SYSTEM

2.3 Event Handlers

The listenerʹs ________ method is invoked after a mouse button is released?

 public void mouseClicked(MouseEvent e) and public void mouseReleased(MouseEvent e)

2.4 Inner Class


A Inner class is a member of another class.

In some applications, you can use an inner class to make programs simple.

An inner class can reference the data and methods defined in the outer class in which it nests, so you do
not need to pass the reference of the outer class to the constructor of the inner class.

 Inner Class can access private instance variables in the enclosing object.

LE PHU BINH 28
BOOK MANAGERMENT SYSTEM

A listener class is designed specifically to create a listener object for a GUI component (e.g., a button).

 It will not be shared by other applications.

 So, it is appropriate to define the listener class inside the frame class as an inner class.

2.5 Anonymous Inner Class


An anonymous inner class must always extend a superclass or implement an interface, but it cannot have
an explicit extends or implements clause.

 An anonymous inner class must implement all the abstract methods in the superclass or in the
interface.

 Inner class listeners can be shortened using anonymous inner classes.

 An anonymous inner class is an inner class without a name.

 It combines declaring an inner class and creating an instance of the class in one step.

An anonymous inner class is declared as follows:

The interface ActionListener should be implemented to listen for a button action event.

2.6 Handling Window Event


Any subclass of the Window class can generate the following window events:

 window opened,

LE PHU BINH 29
BOOK MANAGERMENT SYSTEM

 closing,

 closed,

 activated,

 deactivated,

 iconified, and

 deiconified.

2.7 Handling Mouse Event

Java provides two listener interfaces, MouseListener and MouseMotionListener, to handle mouse events.

 The MouseListener listens for actions such as when the mouse is

 pressed,

 released,

 entered,

 exited, or

 clicked.

 The MouseMotionListener listens for actions such as

 dragging or

 moving the mouse.

2.8 Handling Keyboard Event


To process a keyboard event, use the following handlers in the KeyListener interface:

 keyPressed(KeyEvent e) is called when a key is pressed.

 keyReleased(KeyEvent e) is called when a key is released.

 keyTyped(KeyEvent e) is called when a key is pressed and then released.

 When a unicode is entered

E.g. To check whether a DELETE key is pressed or released,

we can only use keyPressed(KeyEvent e) or keyReleased(KeyEvent e).

2.9 The KeyEvent Class


Methods:

 getKeyChar()

LE PHU BINH 30
BOOK MANAGERMENT SYSTEM

 getKeyCode()

Key Constants

 VK_HOME: the Home key

 VK_END: the End key

 VK_PGUP: the Page Up key

 VK_PGDN: the Page Down key

2.10 The Timer Event Class


Some non-GUI components can fire events.

The javax.swing.Timer class is a source component that fires an ActionEvent at a predefined rate.

 You must always specify a listener when creating a Timer object

 You can add multiple listeners for a Timer object

 You can specify a delay using the setDelay method.

Advantages Disadvantages

1. Flexibility 1. Complex

 Programmers that use event-driven can be altered For simple programs, event-driven programming is
easily if the programmer wants something to be often more complex and cumbersome than batch
changed. This paradigm allows the programmer to programming.
produce a form of their requirements.
2. Less Logical and Obvious
Programmers who are event-driven can be put
together without too many problems and also the The flow of the program is usually less logical and
code and design can be easily altered because if obvious
something isn't right. 3. Difficult to find Error
2. Suitability for Graphical Interfaces Errors can be more difficult to spot than with
 Event-driven allows the user to select different simpler, procedural programs.

LE PHU BINH 31
BOOK MANAGERMENT SYSTEM

tools from the toolbar to directly create what they 4. Slower


need such as buttons, radio buttons, etc.
Programs with complex GUIs may be slower to
This also allows people to put objects where they load and run than simpler programs particularly
want them and can directly edit. Some people find if RAM is insufficient.
it easier to directly click on the thing they want to
edit. 5. Confusing

3. Simplicity of Programming Programs with too many forms can be very


confusing and/or frustrating for the user
Event-driven can make programming easier for
some by being able to directly edit the object you 6. Tight Coupling
want the code for. Possible tight coupling between the event schema
Another thing that can make the programming and the consumers of the schema.
easier is that when using an event driven language 7. Blocking
such as visual basic it usually has predictive coding
so when the user is coding it will predict what you Reasoning about blocking operations might be
want to do from what you are typing. becoming more difficult.

4. Easy to Find Natural Dividing Lines

it is easy to find natural dividing lines for unit


testing infrastructure.

5. Highly Compostable

It is highly compostable.

6. Simple and Understandable

It allows for a very simple and understandable


model for both sides of the DevOps Bridge.

7. Purely Procedural and Purely Imperative

Both purely procedural and purely imperative


approaches get brittle as they grow in length and
complexity.

8. A good way to Model Systems

It is one good way to model systems that need to be


both asynchronous and reactive.

9. Allows for more Interactive Programs

It allows for more interactive programs. Almost all


modern GUI programs use event-driven
programming.

LE PHU BINH 32
BOOK MANAGERMENT SYSTEM

10. Using Hardware Interrupts

It can be implemented using hardware interrupts,


which will reduce the power used by the computer.

11. Allows sensors and other hardware

It allows sensors and other hardware to easily


interact with software.

Principles of Event-Driven Programming

 A set of functions that handle events. Depending on the implementation these can be blocking or
non-blocking.

 A mechanism for binding the registered functions to events.

 The main loop (or loops, if you are brave) which constantly polls for new events and calls the
matching event handler(s) when a registered event is received.

5. The Relationship between Procedure, Object Oriented and Event


Driven Programming

The relation of ‘Procedure’ and ‘Object Oriented’ Programming


Procedural programming means that you define a program and its subprograms as a series of steps. In
contrast, declarative programs try to describe the result without regard to the steps taken to computer it
but rather some description or denotation of the desired result.

Object oriented programming is a way of organizing code around the principles of encapsulation,
inheritance, substitution, programming to interfaces, and so on. Object oriented programs are usually
mostly procedural.

Event based programming is about writing event handling procedures and having the core event loop
provided by the underlying system. In this way you can save the trouble of writing your own event loop
and benefit from various libraries that already work with the system provided event loop. Event based
programs are very often writing using object oriented style, but not always.

These three categories are thus not related strictly hierarchically, but in common usage they are mostly
nested within one another.

LE PHU BINH 33
BOOK MANAGERMENT SYSTEM

The relation of ‘Event Driven’ and ‘Object Oriented’ Programming


1. Object Oriented Programming (OOP) and Event-Driven Programming (EDP) are orthogonal,
which means that they can be used together.

2. In OOP with EDP all OOP principles (encapsulation, inheritance and polymorphism) stay intact.

3. In OOP with EDP objects acquire some mechanism of publishing event notifications and
subscribing to event notifications from other objects.

4. The difference between OOP with / without EDP is control flow between objects.

 In OOP without EDP control moves from one object to another object on a method call.
Object mainly invokes methods of other objects.

 In OOP with EDP control moves from one object to another object on event notification.
Object subscribes on notifications from other objects, then waits for notifications from the
objects it is subscribed on, does some work based on notification and publishes it's own
notifications.

5. Conclusion: OOP+EDP is "exactly our old friend OOP" with control flow inverted thanks to
Event-Driven Design.

Why is Event-Driven Programming Object Oriented?

Visual Basic is not an "Object-Oriented Language" its "Object-based Language" because, in VB we


cannot implement Object-Oriented Concepts like Inheritance, Polymorphism, Encapsulation,
and Abstraction.

But it is an Event drive programming, easy to develop applications. VB is used to Develop Graphical
User Interface Applications (GUIs).

VB is Object-Based Event-Driven Programming Language as we use Objects to create our Applications


such as Text Box, Command Button on Form and it is also called Event Driven Language because
anything we do on VB application such as Click Mouse on command Button to execute any command or
enter the text in a text box, etc.

Everything is an event that's why we call it Object-Based, Event-Driven Programming

LO3. Implement basic algorithms in code using an IDE.

1. General introduction
Design a Library Management System

A Library Management System is a software built to handle the primary housekeeping functions of a
library. Libraries rely on library management systems to manage asset collections as well as relationships

LE PHU BINH 34
BOOK MANAGERMENT SYSTEM

with their members. Library management systems help libraries keep track of the books and their
checkouts, as well as members’ subscriptions and profiles.

Library management systems also involve maintaining the database for entering new books and recording
books that have been borrowed with their respective due dates.

2. System Requirements
We will focus on the following set of requirements while designing the Library Management System:

1. Any library member should be able to search books by their title, author, subject category as well
by the publication date.

2. Each book will have a unique identification number and other details including a rack number
which will help to physically locate the book.

3. There could be more than one copy of a book, and library members should be able to check-out
and reserve any copy. We will call each copy of a book, a book item.

4. The system should be able to retrieve information like who took a particular book or what are the
books checked-out by a specific library member.

5. There should be a maximum limit (5) on how many books a member can check-out.

6. There should be a maximum limit (10) on how many days a member can keep a book.

7. The system should be able to collect fines for books returned after the due date.

8. Members should be able to reserve books that are not currently available.

9. The system should be able to send notifications whenever the reserved books become available, as
well as when the book is not returned within the due date.

10. Each book and member card will have a unique barcode. The system will be able to read barcodes
from books and members’ library cards.

3. Diagram
We have three main actors in our system:

 Librarian: Mainly responsible for adding and modifying books, book items, and users. The
Librarian can also issue, reserve, and return book items.

 Member: All members can search the catalog, as well as check-out, reserve, renew, and return a
book.

 System: Mainly responsible for sending notifications for overdue books, canceled reservations,
etc.

 Here are the top use cases of the Library Management System:

LE PHU BINH 35
BOOK MANAGERMENT SYSTEM

 Add/Remove/Edit book: To add, remove or modify a book or book item.

 Search catalog: To search books by title, author, subject or publication date.

 Register new account/cancel membership: To add a new member or cancel the membership of an
existing member.

 Check-out book: To borrow a book from the library.

 Reserve book: To reserve a book which is not currently available.

 Renew a book: To reborrow an already checked-out book.

 Return a book: To return a book to the library which was issued to a member.

LE PHU BINH 36
BOOK MANAGERMENT SYSTEM

4. Code
Here is the code for the use cases mentioned above:

1.Check-out a book,

2.Return a book, and

3.Renew a book.

LE PHU BINH 37
BOOK MANAGERMENT SYSTEM

Note: This code only focuses on the design part of the use cases. Since you are not required to write a
fully executable code in an interview, you can assume parts of the code to interact with the database,
payment system, etc.

Enums and Constants: 


Here are the required enums, data types, and constants:

LE PHU BINH 38
BOOK MANAGERMENT SYSTEM

Database : 
These classes represent various people that interact with our system:

LE PHU BINH 39
BOOK MANAGERMENT SYSTEM

LE PHU BINH 40
BOOK MANAGERMENT SYSTEM

LE PHU BINH 41
BOOK MANAGERMENT SYSTEM

LE PHU BINH 42
BOOK MANAGERMENT SYSTEM

BookGUI
BookReservation, BookLending, and Fine: These classes represent a book reservation, lending, and fine
collection, respectively.

LE PHU BINH 43
BOOK MANAGERMENT SYSTEM

LE PHU BINH 44
BOOK MANAGERMENT SYSTEM

LE PHU BINH 45
BOOK MANAGERMENT SYSTEM

LE PHU BINH 46
BOOK MANAGERMENT SYSTEM

1. Test

Input

Login
I have created this function to enable the user and the admin login. So, initially when a user logs in for the
first time, that user will be an admin by default, and the username and password will be {admin, admin}.
Refer below.

LE PHU BINH 47
BOOK MANAGERMENT SYSTEM

For this schema, I have considered only one admin. So, once a user logs in as an admin, he or she will be
redirected to the admin menu as below. I will discuss the functions of the admin in the admin
menu section.

Connect
The connect function is used to connect the database to the GUI.

In the above function, we are connecting our database with the username “root” and password


“edureka” to our application. Now, once the application is connected to the database, our next step is to
create or reset the database. So, next in this article on Library Management System Project in Java, let us
discuss the Create function..

Create
The create function is used to create the database, tables and add data into these tables. So, to do that,  
statements will be used.

Now, that we have created the database, connected with GUI and enables the login function, next in this
article on Library Management System Project in Java, let us now discuss the functions of the User
Menu.

User Menu
The User Menu is designed to show details of all the books present in the library and the books issued by
the user.

Admin Menu
The Admin Menu is designed to show details of users, books, issued books, add books, return books, add
user, and create or reset the database.

Now that you have understood all the functions, let us execute our library management system project in
Java and see the outputs.

Output
Execute the application by clicking on the run button. Once, you execute you will see the below dialog
box. In the below dialog box, mention username and password as {admin, admin}. Then click on the
Login button.

LE PHU BINH 48
BOOK MANAGERMENT SYSTEM

Once you click on the Login button, you will see the below dialog box opening up.

Here you have various options which you can explore. So, let us start with the first one:

View book
Once, you click on View Books button, you will see the below frame displaying all the books present in
the database, with their details.

View User
The View Users button is used to view the current users on the system. Since we just have only one user
present i.e the admin, it will show you output as below:

LE PHU BINH 49
BOOK MANAGERMENT SYSTEM

Create/Reset
This functionality is used to create or reset a database. So, once you click on the button Create/Rest, you
will see the below output:

Add User
To add a user, click on the option “Add User” and mention details such as username, password and
choose the radio button user or admin. By default, it will be the user. Then, click on Create.

LE PHU BINH 50
BOOK MANAGERMENT SYSTEM

Once the user is created, you will see an output as below:

Now, again if you click on View Users button, you will see the below output:

Alright, so now that we have added a user. Let us say, that particular user wants to issue books. To do
that, the user has to choose the option of Issue Book.

Issue Book
Suppose, if you are the user, once you click on the Issue Book button, you have to mention the Book ID,
User ID, Period(Number of days for issuing the book), and the Issue Date as follows:

LE PHU BINH 51
BOOK MANAGERMENT SYSTEM

Then click on Submit. Once, you click on Submit, you will see the below dialog box:

Now, if you want to see the issued books details, you can use the View Issued Books functionality.

View Issued Books


Once you click on this button, you will see the following output:

Alright, so, now if the user logs in to the system, using the login function, as below:

LE PHU BINH 52
BOOK MANAGERMENT SYSTEM

Then the user will see the below User Menu.

Here, the user can view all the books in the database by using the View Books option and the books
issued by the user in the My Books section as below:

Now, if you wish to return the book, then you have to choose the option of Return Book.

Return Book
Once, you click on the Return Book, mention the Issue ID and the return date as below. Then click
on Return.

LE PHU BINH 53
BOOK MANAGERMENT SYSTEM

Then, you see a message box displaying the fine.

After that, you again see a dialog box, showing the message “Book Returned“. Refer below.

Now, if you click on the View Issued Books, you will see the below output:

Lastly, if you wish to add a book, you can use the option of Add Book.

Add Book
Click on the Add Book button, and mention the book name, genre and price. Then, click on
the Submit button. Refer below.

LE PHU BINH 54
BOOK MANAGERMENT SYSTEM

Apart from this, you can also, see the added books in the View Books section as below:

LO4. Determine the debugging process and explain the


importance of a coding standard.

1. Debugging

1.1 Definition
Debugging is the process of detecting and removing of existing and potential errors (also called as ‘bugs’)
in a software code that can cause it to behave unexpectedly or crash. To prevent incorrect operation of a

LE PHU BINH 55
BOOK MANAGERMENT SYSTEM

software or system, debugging is used to find and resolve bugs or defects. When various subsystems or
modules are tightly coupled, debugging becomes harder as any change in one module may cause more
bugs to appear in another. Sometimes it takes more time to debug a program than to code it.

1.2 Description

To debug a program, user has to start with a problem, isolate the source code of the problem, and then fix
it. A user of a program must know how to fix the problem as knowledge about problem analysis is
expected. When the bug is fixed, then the software is ready to use. Debugging tools (called debuggers)
are used to identify coding errors at various development stages. They are used to reproduce the
conditions in which error has occurred, then examine the program state at that time and locate the cause.
Programmers can trace the program execution step-by-step by evaluating the value of variables and stop
the execution wherever required to get the value of variables or reset the program variables. Some
programming language packages provide a debugger for checking the code for errors while it is being
written at run time.

1.3 Debugging Process:


1.Reproduce the problem.
2.Describe the bug. Try to get as much input from the user to get the exact reason.
3.Capture the program snapshot when the bug appears. Try to get all the variable values and states of the
program at that time.
4.Analyse the snapshot based on the state and action. Based on that try to find the cause of the bug.
5.Fix the existing bug, but also check that any new bug does not occur.

EXAMPLE:

Launching and Debugging

A Java program can be debugged simply by right clicking on the Java editor class file from Package
explorer. Select Debug As → Java Application or use the shortcut Alt + Shift + D, J instead.

LE PHU BINH 56
BOOK MANAGERMENT SYSTEM

Either actions mentioned above creates a new Debug Launch Configuration and uses it to start the Java
application.

Breakpoints

A breakpoint is a signal that tells the debugger to temporarily suspend execution of your program at a
certain point in the code.

To define a breakpoint in your source code, right-click in the left margin in the Java editor and
select Toggle Breakpoint. Alternatively, you can double-click on this position.

LE PHU BINH 57
BOOK MANAGERMENT SYSTEM

The Breakpoints view allows you to delete and deactivate Breakpoints and modify their properties.

All breakpoints can be enabled/disabled using Skip All Breakpoints. Breakpoints can also be
imported/exported to and from a workspace

Debug Perspective

The debug perspective offers additional views that can be used to troubleshoot an application like
Breakpoints, Variables, Debug, Console etc. When a Java program is started in the debug mode, users are
prompted to switch to the debug perspective.

 Debug view – Visualizes call stack and provides operations on that.

 Breakpoints view – Shows all the breakpoints.

LE PHU BINH 58
BOOK MANAGERMENT SYSTEM

 Variables/Expression view – Shows the declared variables and their values.


Press Ctrl+Shift+d or Ctrl+Shift+i on a selected variable or expression to show its value. You can
also add a permanent watch on an expression/variable that will then be shown in the Expressions
view when debugging is on.

 Display view – Allows to Inspect the value of a variable, expression or selected text during
debugging.

 Console view – Program output is shown here.

Stepping commands

LE PHU BINH 59
BOOK MANAGERMENT SYSTEM

1.4 Debugging Strategies:


 Study the system for the larger duration in order to understand the system. It helps debugger to
construct different representations of systems to be debugging depends on the need. Study of the
system is also done actively to find recent changes made to the software.

 Backwards analysis of the problem which involves tracing the program backward from the location
of failure message in order to identify the region of faulty code. A detailed study of the region is
conducting to find the cause of defects.

 Forward analysis of the program involves tracing the program forwards using breakpoints or print
statements at different points in the program and studying the results. The region where the wrong
outputs are obtained is the region that needs to be focused to find the defect.

 Using the past experience of the software debug the software with similar problems in nature. The
success of this approach depends on the expertise of the debugger.

1.5 Debugging Tools:


Debugging tool is a computer program that is used to test and debug other programs. A lot of public
domain software like gdb and dbx are available for debugging. They offer console-based command line
interfaces. Examples of automated debugging tools include code based tracers, profilers, interpreters, etc.
Some of the widely used debuggers are:

 Radare2

 WinDbg

 Valgrind

1.6 Difference Between Debugging and Testing:


Debugging is different from Testing Testing focuses on finding bugs, errors, etc whereas debugging starts
after a bug has been identified in the software. Testing is used to ensure that the program is correct and it
was supposed to do with a certain minimum success rate. Testing can be manual or automated. There are
several different types of testing like unit testing, integration testing, alpha and beta testing, etc.
Debugging requires a lot of knowledge, skills, and expertise. It can be supported by some automated tools
available but is more of a manual process as every bug is different and requires a different technique,
unlike a pre-defined testing mechanism.

LE PHU BINH 60
BOOK MANAGERMENT SYSTEM

2. The importance of a coding standard


Different modules specified in the design document are coded in the Coding phase according to the
module specification. The main goal of the coding phase is to code from the design document prepared
after the design phase through a high-level language and then to unit test this code.

Good software development organizations want their programmers to maintain to some well-defined and
standard style of coding called coding standards. They usually make their own coding standards and
guidelines depending on what suits their organization best and based on the types of software they
develop. It is very important for the programmers to maintain the coding standards otherwise the code
will be rejected during code review.

Purpose of Having Coding Standards:

 A coding standard gives a uniform appearance to the codes written by different engineers.

 It improves readability, and maintainability of the code and it reduces complexity also.

 It helps in code reuse and helps to detect error easily.

 It promotes sound programming practices and increases efficiency of the programmers.

Some of the coding standards are given below:

1. Limited use of globals:


These rules tell about which types of data that can be declared global and the data that can’t be.

2. Standard headers for different modules:


For better understanding and maintenance of the code, the header of different modules should follow
some standard format and information. The header format must contain below things that is being used in
various companies:

Name of the module

 Date of module creation

 Author of the module

 Modification history

 Synopsis of the module about what the module does

 Different functions supported in the module along with their input output parameters

 Global variables accessed or modified by the module

3. Naming conventions for local variables, global variables, constants and functions:
Some of the naming conventions are given below:

 Meaningful and understandable variables name helps anyone to understand the reason of using it.

LE PHU BINH 61
BOOK MANAGERMENT SYSTEM

 Local variables should be named using camel case lettering starting with small letter (e.g. localData)
whereas Global variables names should start with a capital letter (e.g. GlobalData). Constant
names should be formed using capital letters only (e.g. CONSDATA).

 It is better to avoid the use of digits in variable names.

 The names of the function should be written in camel case starting with small letters.

 The name of the function must describe the reason of using the function clearly and briefly.

4. Indentation:
Proper indentation is very important to increase the readability of the code. For making the code readable,
programmers should use White spaces properly. Some of the spacing conventions are given below:

 There must be a space after giving a comma between two function arguments.

 Each nested block should be properly indented and spaced.

 Proper Indentation should be there at the beginning and at the end of each block in the program.

 All braces should start from a new line and the code following the end of braces also start from a new
line.

5. Error return values and exception handling conventions:


All functions that encountering an error condition should either return a 0 or 1 for simplifying the
debugging.

On the other hand, Coding guidelines give some general suggestions regarding the coding style that to be
followed for the betterment of understandability and readability of the code. Some of the coding
guidelines are given below :

6. Avoid using a coding style that is too difficult to understand:


Code should be easily understandable. The complex code makes maintenance and debugging difficult and
expensive.

7. Avoid using an identifier for multiple purposes:


Each variable should be given a descriptive and meaningful name indicating the reason behind using it.
This is not possible if an identifier is used for multiple purposes and thus it can lead to confusion to the
reader. Moreover, it leads to more difficulty during future enhancements.

8. Code should be well documented:


The code should be properly commented for understanding easily. Comments regarding the statements
increase the understandability of the code.

9. Length of functions should not be very large:


Lengthy functions are very difficult to understand. That’s why functions should be small enough to carry
out small work and lengthy functions should be broken into small ones for completing small tasks.

LE PHU BINH 62
BOOK MANAGERMENT SYSTEM

10.Try not to use GOTO statement:


GOTO statement makes the program unstructured, thus it reduces the understandability of the program
and also debugging becomes difficult.

Advantages of Coding Guidelines:

Coding guidelines increase the efficiency of the software and reduces the development time.

Coding guidelines help in detecting errors in the early phases, so it helps to reduce the extra cost incurred
by the software project.

If coding guidelines are maintained properly, then the software code increases readability and
understandability thus it reduces the complexity of the code.

It reduces the hidden cost for developing the software.

Referance
1.Difference between procedural programming and object-oriented programming(
https://www.javatpoint.com/procedural-programming-vs-object-oriented-programming )

2.What are the steps taken from writing code to execution? (https://www.quora.com/What-are-the-steps-
taken-from-writing-code-to-execution)

3 .6 Stages for Software Development Procedure You Need to Know (


https://saigontechnology.com/blog/6-stages-for-software-development-procedure-you-need-to-know )

6. Procedural Programming ( https://hackr.io/blog/procedural-programming)

7. Object Oriented Programming (OOPs) Concept in Java

( https://www.geeksforgeeks.org/object-oriented-programming-oops-concept-in-java )

8. Advantages and Disadvantages of Event-Driven Programming ( https://benchpartner.com/advantages-


and-disadvantages-of-event-driven-programming )

9. Java - GUI and Event driven programming ( https://vinesmsuic.github.io/2020/11/09/java-


eventdriven/#event-driven-programming )

LE PHU BINH 63
BOOK MANAGERMENT SYSTEM

10. Event-Driven Programming in Java: Definition & Compone (


https://study.com/academy/lesson/event-driven-programming-in-java-definition-
components.html#:~:text=In%20Java%20GUI%20applications%20using,to%20as%20being%20event
%2Ddriven. )

11. Design a Library Management System ( https://www.educative.io/courses/grokking-the-object-


oriented-design-interview/RMlM3NgjAyR )

12. Book class ( https://gist.github.com/Mahkul/911344 )

13. How to create library managerment system project in Java ( https://www.edureka.co/blog/library-


management-system-project-in-java )

14. Softwere Engineering | Debugging ( https://www.geeksforgeeks.org/software-engineering-debugging/


)

15. Debugging the Eclipse IDE for Java Developers (


https://www.eclipse.org/community/eclipse_newsletter/2017/june/article1.php#:~:text=A%20Java
%20program%20can%20be,to%20start%20the%20Java%20application. )

16. Coding Standards and Guidelines (


https://www.geeksforgeeks.org/coding-standards-and-guidelines/#:~:text=A%20coding%20standard
%20gives%20a,helps%20to%20detect%20error%20easily. )

LE PHU BINH 64

You might also like