0% found this document useful (0 votes)
35 views54 pages

PROG191

At my library, people are using books more frequently right now for both enjoyment and informational purposes. This results in manual library management, which makes it challenging, time-consuming, and impossible for us to maintain the proper level. As a result, I made the decision to write a Java application that enables book management. I can regulate the pricing and quantity of the book and know its exact contents thanks to this software.

Uploaded by

WynT
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views54 pages

PROG191

At my library, people are using books more frequently right now for both enjoyment and informational purposes. This results in manual library management, which makes it challenging, time-consuming, and impossible for us to maintain the proper level. As a result, I made the decision to write a Java application that enables book management. I can regulate the pricing and quantity of the book and know its exact contents thanks to this software.

Uploaded by

WynT
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 54

PROG191

Student’s name: NGUYEN NHAT THANH

ID: GCS210101

Class: GCS1003A
Subject code: PROG191
Assessor name: LAM NGUYEN TRUNG NAM

lOMoARc PSD|14 518471


1|Page
lOMoAR cPSD| 14518471

ASSIGNMENT 1 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing

Unit number and title

Submission date 2022 Date Received 1st submission

Re-submission Date Date Received 2nd submission

Student Name Nguyen Nhat Thanh Student ID GCS210101

Class GCS1003A Assessor name Lam Nguyen Trung Nam

Student declaration
I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I understand that
making a false declaration is a form of malpractice.

Student’s signature Thanh


Grading grid

Grade (0-10)

T r a n g 1 | 52
lOMoAR cPSD| 14518471

❒ Summative Feedback: ❒ Resubmission Feedback:

Grade: Assessor Signature: Date:


IV Signature:

T r a n g 2 | 52
lOMoAR cPSD| 14518471
lOMoAR cPSD| 14518471

Table of contents:
I. Introduction............................................................................................................................................................................ 4

II. Requirement:......................................................................................................................................................................... 4

III. UI design .................................................................................................................................................................................5

IV. Implementation

1. Explain program structure: ..................................................................................................................................................... 6

2. Explain classes ......................................................................................................................................................................... 9

3. Explain important algorithms.................................................................................................................................................. 15

4. Explain how to handle errors: ................................................................................................................................................. 31

V. Test:

1. Junit Test .................................................................................................................................................................................. 34

2. Test Case .................................................................................................................................................................................. 40

VI. Result: ......................................................................................................................................................................................41

VII. Conclusion .............................................................................................................................................................................. 52

T r a n g 3 | 52
lOMoAR cPSD| 14518471

I. Introduction:
At my library, people are using books more frequently right now for both enjoyment and informational purposes. This
results in manual library management, which makes it challenging, time-consuming, and impossible for us to maintain
the proper level. As a result, I made the decision to write a Java application that enables book management. I can regulate
the pricing and quantity of the book and know its exact contents thanks to this software.
II. Requirement
I was able to resolve some of the following issues with the aid of the java application I wrote:

-I can simply and clearly input data and amend and remove it.

-I can use the search feature to get details on the item I'm looking for.

-I may access the program's file reading and writing feature to review the data I've already entered.

III. UI design

T r a n g 4 | 52
lOMoAR cPSD| 14518471

T r a n g 5 | 52
lOMoAR cPSD| 14518471

The basic interface of the program will include labels, corresponding to it are text fields and combo boxes for users to
enter corresponding information. Besides, there are buttons for users to interact with the entered data. Finally, atable to
display the entered results.

IV. Implementation
1. Explain program structure

I write a Java program that has two primary components: a class called book.java and a Jframe called bookManagement.java.

Then, member variables with methods are declared using the class I defined. After that, I'll utilize them to fill the Jframe
I made. I'll use that to develop functions for my software.
I based my program interface design on the wireframe I had already constructed, giving each piece a variable name
(button, text field, label, table, combo box,... )

T r a n g 6 | 52
lOMoAR cPSD| 14518471

T r a n g 7 | 52
lOMoAR cPSD| 14518471

T r a n g 8 | 52
lOMoAR cPSD| 14518471

2. Explain classes
In this class, I have imported the respective libraries to use the variables that I created:

To prevent duplication with the variables I use in the Jframe, I have designated the local variables of the proper type
(string, integer, etc.) as private and limited their use to this class.

Then I declare methods using variable declarations. I push the data into the Jframe using those techniques.
The initialization approach is the first. I initialize the objects I defined earlier using this function. This enables me to call
other equivalent methods to setup the logic inside the objects as well as to set values for attributes inside it.

T r a n g 9 | 52
lOMoAR cPSD| 14518471

I then apply java's encapsulation through getter and setter methods to define accessibility for the privateproperties I
initialized above and allow those properties to be viewed and modified.

T r a n g 10 | 52
lOMoAR cPSD| 14518471

T r a n g 11 | 52
lOMoAR cPSD| 14518471

T r a n g 12 | 52
lOMoAR cPSD| 14518471

I use inheritance in Java on this class. I may obtain the hashcode value of the aforementioned initialized components by
invoking the hashCode() function. In addition, I utilize the equals()) function to compare two objects in a meaningful
way (by comparing the data members of the class).

T r a n g 13 | 52
lOMoAR cPSD| 14518471

T r a n g 14 | 52
lOMoAR cPSD| 14518471

3. Explain important algorithms


I built my program on JFrame which I created as follows:
Firstly, I have imported the libraries that I will use in my program:

T r a n g 15 | 52
lOMoAR cPSD| 14518471

I established a new List called bookList that is linked from the Book.java class that I generated, and I specified properties
like file (for file read and write capabilities), a memory variable that is model to use, and bookManagement in the
bookManagement class. Two integer variables, index and editIndex, are utilized to show information.

T r a n g 16 | 52
lOMoAR cPSD| 14518471

Then I instantiate a new method called bookManagement , which contains the values of the propertiescreated above.
I will use them to pass values to the methods and functions below.

To show the data displayed under the labels Total, Borrowed, and BorrowedCost, which are needed to determine the total
number of books, the number of books to borrow, and the sum of books to be borrowed, I initialize the thongke array.

T r a n g 17 | 52
lOMoAR cPSD| 14518471

By using a for loop provided that when more information from the bookList is added, the values corresponding to
the variables will be added together, then their results will be displayed in the labels. Imade it available

I create a method writeFile that writes the file to memory, then a read File method that makes the data that Ihave
entered displayed after I restart the program again.

T r a n g 18 | 52
lOMoAR cPSD| 14518471

I initialize the variables fileOutputStream and outputStream with a value of null in the writeFile array with the input
bookList variable. To transmit the value of the initialized file variable into this method, I use try... to catch the exception.
I employ a for loop to ensure that the writeObject function, which uses the variable b as the bookList, is called each time
a value is added to memory. I mark the conditions printed on the screen in the catch section as being unacceptable. I
conclude the technique with one more try and a catch.

T r a n g 19 | 52
lOMoAR cPSD| 14518471

Similarly, in the readFile array with the input bookList variable, I initialized 2 variables fileInputStream and inputStream with
the initial value of null. I use try ... to catch the exception through which to pass the value

T r a n g 20 | 52
lOMoAR cPSD| 14518471

of the initialized file variable to this method. I use a while loop so that every time a value is added to memory, the
readObject method with the book variable will be executed, and the add() method will also beexecuted to display it on
the screen. In the catch, I leave the print conditions to the screen as unsatisfactory.Finally I end the method with
another try..catch exception method to remove unsatisfied conditions

I've initialized the event at the Search function. In particular, I use the input value from txtSearch to populate the variable
tukhoa. I use the data from the previously constructed book array to create the results array. If the user inputs a search
term and produces a new variable str, I utilize if...else repetition. In this loop, I first use a for loop with the condition that
the str variable will always be assigned a value equal to the values TacJoin in, and then I use an if.. loop..else loop with
the condition that the results variable will always be increased if the str variable contains the character tukhoa.

T r a n g 21 | 52
lOMoAR cPSD| 14518471

Then I use the removeAllElements method to remove all the rows and fireTableDataChanged to put the datain the
table. To put the data into the table, I use a for loop condition every time a value is found with the variable i =0
incremented after each loop, the information is displayed to the table with the fireTableDataChanged method. I list the
value obtained below with the size() method

I then create methods and verify the requirements for user input. I use if..else to examine the criteria concerning the
quantity limit. I catch the try..catch event and inspect the try..catch event for conditions pertaining to the input value.

T r a n g 22 | 52
lOMoAR cPSD| 14518471

T r a n g 23 | 52
lOMoAR cPSD| 14518471

With the function to add values to the table, I declare the input values with new variables. Then use if...elseloop to
check the condition and return the corresponding values. If the user enters correctly, the value will

T r a n g 24 | 52
lOMoAR cPSD| 14518471

be displayed according to each column in the table. If the user enters the wrong condition, I have written thecode so
that the system will display the correct input condition message.

T r a n g 25 | 52
lOMoAR cPSD| 14518471

To delete or correct information, I create a new event called MouseCLicked so the user can click on any rowin the
table and interact with it with an if loop.

T r a n g 26 | 52
lOMoAR cPSD| 14518471

I also declare the input values using a new variable along with the method to modify the value in the table. Then, to verify
the situation and return the appropriate numbers, use the if... else loop. If the user inputs the value properly, the
editedIndex variable will be increased and the value will be displayed for each column in the table. I have built the code
to make the system display the proper input condition message if the user enters the incorrect condition.
T r a n g 27 | 52
lOMoAR cPSD| 14518471

T r a n g 28 | 52
lOMoAR cPSD| 14518471

When a user clicks a line to remove, I utilize an if loop with the delete function. To verify if the user should be deleted,
I used the showConfirmDialog function. Because I created an if loop with a descending index variable, the removeRow
method to remove the row, and the thongke function to display the table after it has been restored, if the user chooses to
delete, the system will remove the data of the user-selected row.

T r a n g 29 | 52
lOMoAR cPSD| 14518471

With the Clear function, I also use the showConfirmDialog method to confirm the user's deletion. Then I usean if loop.
If user confirm want to delete, system will delete all data because I used removeAllElements . method

T r a n g 30 | 52
lOMoAR cPSD| 14518471

4. Explain how to handle errors


When the user uses add or edit feature, the following error may occur:

T r a n g 31 | 52
lOMoAR cPSD| 14518471

This error occurs when the user enters data that is not within the range I created. To fix this error, pleaseenter the
correct data in the limited range.

T r a n g 32 | 52
lOMoAR cPSD| 14518471

Or the below error may occur:

This is a mistake since the user didn't enter all the necessary ranges or left some out. Please provide accurate and complete
information to help resolve this issue.

T r a n g 33 | 52
lOMoAR cPSD| 14518471

Below is the result after entering complete and correct information:

V. Test
1. Junit Test :
JUnit is a framework for Java programming language unit testing. It is a crucial component of test-driven software
development and one of the xUnit frameworks for unit testing.
A unit test case is a section of code that checks if a program's methods (another portion of the code) function as intended.
A testing framework is necessary for a software project to swiftly get the appropriate results. The Java programming
language's unit testing framework, JUnit, is ideal.
An expected outcome and a given input make up a unit test case. T r a n g 34 | 52
lOMoAR cPSD| 14518471

There must be at least two single test units for each requirement - one positive and one negative. If the requirement has sub-
requirements, each sub-requirement must have at least two test cases, positive test andnegative test.

Here are my test results using JUnit:

T r a n g 35 | 52
lOMoAR cPSD| 14518471

If I don't code in Test classes, meaning I don't change anything in the class I created, JUnit returns me 100%complete:

T r a n g 36 | 52
lOMoAR cPSD| 14518471

If I code my test and run it, the outcome is skewed from the original and is 94%. This is so because the intended outcome
is " ", but the return value of this Test class is null. Therefore, the software cannot be 100% complete if the user inputs
the incorrect type of information since the system would produce an error:

2. Test Case:
My test plan will involve data entry as well as code input during program building

T r a n g 37 | 52
lOMoAR cPSD| 14518471

Test case Test Action Test Type Results Expected


Outcome
In java class Declare variable Enter correct data Normal The program runs The program
normally runs normally

Wrong data input Error Error reporting


system

In java Jframe Read and Write Right path Normal The system runs The system runs
File normally, the file normally, the file
reading and reading and writing
writing functions functionsare still
are still executed, executed,and the
and the user can user can still see
still see the the previous
previous information
information display.
display.

Wrong path Error The system runs


normally, the file
reading and writing
functions are still
executed.However,
when the user pops
up,the previous
information is not
displayed again.

T r a n g 38 | 52
lOMoAR cPSD| 14518471

In the process of Ceclare correct Normal The system runs The system runs
writing code variable normally normally
properties,
information
Ceclare wrong Error The system is still
variable running, but the
properties, displayed
information information is
missing or not
displayed.

Incorrect syntax Error The system


reported an error
that the program
could not be run
due to incorrect
syntax

In the process of Enter the correct Normal The system runs The system runs
running the code data type normally normally

Enter the wrong Error The system is still


data type running normally,
the file reading and
writing functions
are still normal. But
when I
press the add, edit
and delete

T r a n g 39 | 52
lOMoAR cPSD| 14518471

functions, the
system will display
an error because I
have added the
error display
function.

VI. Result

T r a n g 40 | 52
lOMoAR cPSD| 14518471

This is the basic interface of the system at runtime.

T r a n g 41 | 52
lOMoAR cPSD| 14518471

T r a n g 42 | 52
lOMoAR cPSD| 14518471

This is the system interface after successfully adding information

T r a n g 43 | 52
lOMoAR cPSD| 14518471

This is the system interface after successfully editing information

T r a n g 44 | 52
lOMoAR cPSD| 14518471

T r a n g 45 | 52
lOMoAR cPSD| 14518471

This is the system interface after successfully searching information

T r a n g 46 | 52
lOMoAR cPSD| 14518471

T r a n g 47 | 52
lOMoAR cPSD| 14518471

This is the system interface after wrong editing or adding information

T r a n g 48 | 52
lOMoAR cPSD| 14518471

thanh

T r a n g 49 | 52
lOMoAR cPSD| 14518471

This is interface when you want to delete a row

T r a n g 50 | 52
lOMoAR cPSD| 14518471

This is interface when you want to delete all

T r a n g 51 | 52
lOMoAR cPSD| 14518471

VII. Conclusion
My program is finished and available for usage. Information may be added, edited, and
deleted using this software. Additionally, there is a search feature that makes it simpler for
users to manage information. Users can verify the previously input data with the help of
the file read and write functions.

This software still has certain restrictions, though:


The user-friendly interface is not very attractive.
Sorting, using the database, and several other features are still lacking.

T r a n g 52 | 52

You might also like