Tải bản đầy đủ (.pdf) (53 trang)

Prog191_Assignment (Merit).Pdf

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.72 MB, 53 trang )

PROG191-Assignment- Java Programming


ASSIGNMENT 1 FRONT SHEET
Qualification

BTEC Level 5 HND Diploma in Computing

Unit number and title
Submission date

June 9th ,2022

Re-submission Date

Date Received 1st submission
Date Received 2nd submission

Student Name

Đào Vĩnh Khang

Student ID

GCS200222

Class

GCS0905B

Assessor name



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

KHANG

Grading grid
Grade (0-10)

T r a n g 1 | 52


❒ Summative Feedback:

Grade:

❒ Resubmission Feedback:

Assessor Signature:

Date:

IV Signature:

Table of contents: I. Introduction:............................................................................................................... Error! Bookmark not defined.
II. Requirement: ............................................................................................................................................................................................................. 4

III. UI design : .................................................................................................................................................................................................................. 4
T r a n g 2 | 52


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 ... 37
VI. Result: ....................................................................................................................................................................................................................... 40
VII. Conclusion: ............................................................................................................................................................................................................ 52

I.

Introduction:
Currently, the use of books to look up information as well as entertainment at my library is increasing. This
leads to manual library management which makes it difficult, delayed and impossible for us to control the right
amount. Therefore, I decided to create an application that supports book management in java language. This
application helps me to know the exact information of the book and control its price and quantity.

T r a n g 3 | 52


II.

Requirement
The java program that I created helped me solve some of the following problems: I can enter data, and can edit and delete them easily and understandably -I
can find information about the product I need through the search function.
-I can review the information I have entered before through the program's file reading and writing


function

III.

UI design

T r a n g 4 | 52


T r a n g 5 | 52


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, a table to display the entered results.

IV.

Implementation 1. Explain program structure
I create a java application, consisting of 2 main parts: 1 class named book.java and 1 Jframe named
bookManagement.java

Then the class I created is used to declare member variables with methods. Then I'll use them to populate
the Jframe I've created. Through that, I will create functions for my program
I designed my program interface based on the wireframe I created above, and set variable names for each
element (button, text field, label, table, combo box,... )

T r a n g 6 | 52



T r a n g 7 | 52


T r a n g 8 | 52


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

I have declared the local variables with the corresponding type (string,integer,...) as private to make them
only used in this class, avoiding duplication with the variables that I use in the Jframe.

Then I declare methods that contain variables. Through those methods, I push the data inside the Jframe.

T r a n g 9 | 52


The first is the initialization method. I use this method to initialize the objects I declared above. This helps
me to initialize values for properties inside it and helps me to call other corresponding methods to initialize
the logic inside the objects.

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

T r a n g 10 | 52


T r a n g 11 | 52



T r a n g 12 | 52


I apply java’s inheritance to this class. Through calling hashCode() method I will get the hashcode value of
the above initialized elements. Combined with that, I use the equals()) method to semantically compare two
objects (by comparing the data members of the class).

T r a n g 13 | 52


T r a n g 14 | 52


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


In the bookManagement class, I have declared properties like file (for file read and write functionality), a
new List named bookList which is linked from the Book.java class that I created, a memory variable which is
model to use Used for information display function, two integer variables index and editIndex are used to
display and interact with information.

T r a n g 16 | 52


Then I instantiate a new method called bookManagement , which contains the values of the properties

created above. I will use them to pass values to the methods and functions below.

I initialize the thongke array with the function of displaying the information printed under the labels Total,
Borrowed, BorrowedCost , used to calculate the total number of books, the number of books to borrow and
the amount of books to be borrowed.

T r a n g 17 | 52


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. I
made it available

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

T r a n g 18 | 52


in the
writeFile array with the input bookList variable, I initialize 2 variables fileOutputStream and outputStream
with the initial value of null. I use try ... to catch the exception through which to pass the value of the
initialized file variable into this method. I use a for loop so that every time a value is added to memory, the
writeObject method with the variable b as bookList will be executed. In the catch part, I leave the
conditions printed to the screen as unsatisfactory. I end the method with finally with another try..catch
exception method to remove unsatisfied conditions
T r a n g 19 | 52


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
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 be

T r a n g 20 | 52


executed 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

At the Search function I have initialized the event for it. Specifically, I initialize a variable tukhoa with the
input value from txtSearch. I create the results array with the values from the book array created above. I
use if...else iteration provided the user enters the Search field and creates a new variable str. In this loop, I
use a for loop with the condition that every time the information is changed, the variable str will be
assigned a value equal to the values TacJoin in, then I use an if.. loop. .else again with the condition that if
the str variable contains tukhoa, the printed result will be increased, that is, the results variable will be
increased.

T r a n g 21 | 52


Then I use the removeAllElements method to remove all the rows and fireTableDataChanged to put the
data in 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
Next, I instantiate methods to check user input conditions. For the conditions involving the quantity limit, I
use if..else to check. For conditions related to the input value, I catch the try..catch event to check them.

T r a n g 22 | 52



T r a n g 23 | 52


With the function to add values to the table, I declare the input values with new variables. Then use if...else loop
to check the condition and return the corresponding values. If the user enters correctly, the value will be
displayed according to each column in the table. If the user enters the wrong condition, I have written the code
so that the system will display the correct input condition message.

T r a n g 24 | 52


Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×