You are on page 1of 27

ASSIGNMENT 1 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing

Unit number and title

Submission date Date Received 1st submission

Re-submission Date Date Received 2nd submission

Student Name Vo Thi Minh Thu Student ID GCD210164

Class GCD1105 Assessor name Nguyen The Nghia

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 thu


Grading grid

Grade (0-10)
❒ Summative Feedback: ❒ Resubmission Feedback:

Grade: Assessor Signature: Date:


IV Signature:
Contents
I. INTRODUCTION ...................................................................................................................................................................................................... 5
II. REQUIREMENT ...................................................................................................................................................................................................... 5
A list of the business problem's needs. .......................................................................................................................................................................... 5
III. UI DESIGN .............................................................................................................................................................................................................. 6
IV. IMPLEMENTATION.............................................................................................................................................................................................. 7
1. Explain Program Structure ..................................................................................................................................................................................... 7
2. SuperClass.............................................................................................................................................................................................................. 8
3. SubClass ElectricBike ............................................................................................................................................................................................ 9
4.. SubClass MultiSeatBike ....................................................................................................................................................................................... 9
5. SubClass RegularBike ......................................................................................................................................................................................... 10
V. Explain Important Algoritms .................................................................................................................................................................................. 11
1. Delete Bike........................................................................................................................................................................................................... 11
2. Add Bike .............................................................................................................................................................................................................. 13
3. Save ...................................................................................................................................................................................................................... 16
4. Load ..................................................................................................................................................................................................................... 19
5. Explain How To Handle Error ............................................................................................................................................................................. 20
6. Test....................................................................................................................................................................................................................... 26
6.1. Test case ........................................................................................................................................................................................................ 26
VI. CONCLUSION...................................................................................................................................................................................................... 27
Figure 1: UI Design ......................................................................................................................................................................................................... 6
Figure 2: program structure .......................................................................................................................................................................................... 7
Figure 3: Item Room...................................................................................................................................................................................................... 8
Figure 4: SubClass ElectricBike ....................................................................................................................................................................................... 9
Figure 5: SubClass MultiSeatBile .................................................................................................................................................................................... 9
Figure 6: SubClass RegularBike .................................................................................................................................................................................... 10
Figure 7: Delete Bike .................................................................................................................................................................................................... 11
Figure 8: Add Bike ........................................................................................................................................................................................................ 14
Figure 9: Save ............................................................................................................................................................................................................... 18
Figure 10: Load............................................................................................................................................................................................................. 19
Figure 11: Handle error 1 ............................................................................................................................................................................................. 22
Figure 12: Handle error 2 ............................................................................................................................................................................................. 23
Figure 13: Handle error 3 ............................................................................................................................................................................................. 24
Figure 14: Handle error 4 ............................................................................................................................................................................................. 25
I. INTRODUCTION
The bicycle rental application is a flexible tool that helps users find, reserve and use bicycles easily. With a friendly interface, it offers
a variety of vehicle options, rental/return locations and online payments, providing a flexible and convenient travel experience.

II. REQUIREMENT

A list of the business problem's needs.


My requests for the product management system are listed below:

A graphical user interface is necessary for the system to facilitate user involvement.

A text file is required to hold the data.

The system allows for the addition, updating, and deletion of data related to each product.

By ID, product details may be obtained.


That's the reason I developed this management system using the Java Swing programming language.

III. UI DESIGN

Figure 1: UI Design
IV. IMPLEMENTATION

1. Explain Program Structure

Figure 2: program structure

This is the code for my directory structure. They are plainly visible, and they include Room.java, a Jframe that houses the interface,
and logic to manage functions.
2. SuperClass

Figure 3: Item Room

The above Java code defines a class named "Bike" to represent information about a bicycle. It includes properties such as bikeID,
name, identityCard, email, timeRent, typeBike, and defaultPrice to store information about the bike ID, owner information, rental
time, bike type, and default rental price. determined.
3. SubClass ElectricBike

Figure 4: SubClass ElectricBike

This code defines a static class named "ElectricBike" that inherits from the "Bike" class. The "ElectricBike" class specializes in
information for electric bicycles. In the constructor of the "ElectricBike" class, it calls the setDefaultPrice(15.0) method to set the
default rental price of the electric bike to 15.0 units (currency or another equivalent unit). This allows the child class (ElectricBike) to
set rental rates differently than the parent class (Bike) it inherits from.

4.. SubClass MultiSeatBike

Figure 5: SubClass MultiSeatBile

The code defines a static class named "MultiSeatBike" that is a type of multi-seat bicycle, inheriting from the "Bike" class. In the
constructor of the "MultiSeatBike" class, the default rental price of this vehicle is set to 20.0 units (currency or other equivalent).
5. SubClass RegularBike

Figure 6: SubClass RegularBike

The code defines a static class "RegularBike" which is a regular type of bicycle, inheriting from class "Bike". In the constructor of the
"RegularBike" class, the default rental price of this vehicle is set to 10.0 units (currency or other equivalent).
V. Explain Important Algoritms

1. Delete Bike

Figure 7: Delete Bike

This code handles the event when the user clicks the delete button on the user interface (GUI). When this button is pressed, the
deleteButtonActionPerformed function is called.

int selectedRowIndex = bikeTable.getSelectedRow();: This line gets the index of the selected row in the table displaying the list of
bicycles.

Check to see if any rows are selected. If no row is selected (selectedRowIndex == -1), an error dialog box appears asking the user to
select a vehicle to delete.
If the user has selected a vehicle, a confirmation dialog is displayed asking to confirm the deletion of the vehicle. If the user selects
"Yes" (confirmation == JOptionPane.YES_OPTION), the row corresponding to the selected car will be removed from the display
panel (model.removeRow(selectedRowIndex)).

Finally, a success message dialog box will be displayed to the user, informing that the vehicle deletion was successful.
2. Add Bike
Figure 8: Add Bike

This code handles the event when the user presses the "Add" button on the user interface to add a new bike's information to the display
panel.

Get information from the input boxes on the interface, including vehicle ID, name, ID card, email, rental time, and vehicle type.

Check if the required information fields are empty. If one of them is empty (id.isEmpty() || bikeName.isEmpty() || idCard.isEmpty() ||
userEmail.isEmpty() || rentTime.isEmpty()), a NumberFormatException will be thrown to report error.

If the information entered is valid, a new Bike object will be created with the information entered. The default rental price and rental
period are also used to calculate the total rental price.

Add information about the new vehicle to the first row of the display table (JTable).

If an error occurs during data entry (for example, an empty field), an error dialog box will appear asking the user to enter the correct
information.
This code checks the input information and adds the new vehicle information to the display table if the information is valid.
3. Save
Figure 9: Save

This code handles the event when the user presses the "Save File" button on the user interface to save the bike information to a text
file.

Create or open the file "bike.txt" to store the information of the bikes.

Browse the display table (JTable) to get information from the cells and write it to the text file "bike.txt".

First, write the column names in the first line of the text file.

Next, for each row in the table, write each cell value to a text file, separated by "," and create a new line after each row.

If the file saving process is successful, display a confirmation message. If an error occurs while saving the file, an error message is
displayed.

This code saves the bike information from the display panel to a text file for later storage or processing.
4. Load

Figure 10: Load

This code handles an event when the user selects a file to load information from that file into the app.

Displays a dialog box allowing the user to select the file to download information.

If the user selects the file and confirms ("Approve"), the selected file is opened and read.

The data in the file will be analyzed and loaded into the display table (JTable).

If the data download is successful, a confirmation message is displayed. If there is an error, an error message will appear.

This code loads information from a stored file and loads it into the application's display panel for use or editing.
5. Explain How To Handle Error
Handle error 1:
Figure 11: Handle error 1

This code creates or writes information from the display table (JTable) to a text file named "bike.txt". Each row in the table will be
recorded as a line in the text file, the values separated by ",".

A BufferedWriter object is created to write information to a text file.

The names of the columns in the table (model.getColumnName(i)) are written to the first line of the text file, each column name
separated by a ",".

Go through each row in the table and each column of that row, get the cell value (cellValue) and write it to the text file. If the cell is
null, an empty string will be written to the file.

Each row will be written to a new line in the text file.

If the file recording is successful, a confirmation message will appear. If there is an error during recording, an error message will
appear to notify the user.
Handel error 2:

Figure 12: Handle error 2

This code reads data from a stored text file and loads it into the application's display table.

A BufferedReader is created to read data from the selected text file (fileToLoad).

Data from a text file is read as an array of lines (tableLines).

The current row count in the display table (model.getRowCount()) is set to zero (model.setRowCount(0)) to remove old data.

Go through each line of data in the text file and separate them based on commas (,). Each row is added to the display table
(model.addRow(dataRow)).

If the data download is successful, a confirmation message is displayed. If there is an error, an error message will appear.

This code loads data from the text file into the application's display panel so it can be viewed or edited.

Handle error 3:
Figure 13: Handle error 3

This code snippet adds information about a new bike to a JTable in your application.

First, the code checks to see if necessary information fields such as ID, name, ID card, email, rental period are empty. If any field is
empty (`id.isEmpty() || bikeName.isEmpty() || idCard.isEmpty() || userEmail.isEmpty() || rentTime.isEmpty()`), it will throw an
exception NumberFormatException rule.

If the information entered is valid, a new `Bike` object is created with the information just entered. The default rental price and rental
period are also used to calculate the total rental price.
The new car's data, including ID, name, ID card, email, rental period, vehicle type and total rental price, are added to a new row of the
display table.

If an error occurs during data entry (for example, an empty field), an error dialog box will appear asking the user to enter the correct
information.

This code checks the input information and adds the new vehicle information to the display table if the information is valid.

Handle error 4:

Figure 14: Handle error 4

This code handles updating a bike's information in the display table (JTable) when the user makes an edit.

First, the code creates a new Bike object based on the edited information from the input cells.

Calculate the rental price and total rental price of the vehicle based on new information.

Updates the vehicle data in the selected row of the display with the new information just entered.
If an error occurs during data entry (for example, entering the wrong number format), an error dialog box will appear.

This code updates a bicycle's information in the display table when there is a change from the user.

6. Test

6.1. Test case


Action Expected Result Actually Result Status
I don't fill any fields in the Display Error Pass
textfield. “Please enter valid data!”.

Enter in the text field. displays the information Pass


below the table.

Click on the row you want The table Update row I Pass
to update, enter the field just confirm Update.
to edit. then click update.

Click the row you want to The table Deleted row I Pass
delete. then click show just confirm Delete.
confirm. I press "yes", the
table deletes the row I
select.
Click save to save display The table Save row I just Pass
save successfully. confirm Save.

Click on load, it will read View, read and display " Pass
and display the data saved bike.txt " data on the table.
in "bike.txt"

VI. CONCLUSION
I have completed my product and it is fully functional as required.

You might also like