Professional Documents
Culture Documents
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.
Grade (0-10)
❒ Summative Feedback: ❒ Resubmission Feedback:
II. REQUIREMENT
A graphical user interface is necessary for the system to facilitate user involvement.
The system allows for the addition, updating, and deletion of data related to each product.
III. UI DESIGN
Figure 1: UI Design
IV. IMPLEMENTATION
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
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
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.
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
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
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
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 ",".
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.
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:
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).
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:
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
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.