Docsity

PROG191-java application-ASM, Essays (university) of Programming Languages

Toggle sidebar
bg1
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
Trinh Nguyen Phuong
Student ID
GCH210876
Class
GCH1101
Assessor name
Dinh Duc Manh
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
PHUONG
Grading grid
Grade (0-10)
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b

Partial preview of the text

Download PROG191-java application-ASM and more Essays (university) Programming Languages in PDF only on Docsity!

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 Trinh Nguyen Phuong Student ID GCH Class GCH1101 Assessor name Dinh Duc Manh 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 PHUONG

Grading grid Grade (0-10)

❒ Summative Feedback: ❒ Resubmission Feedback:

Grade: Assessor Signature: Date: IV Signature: I. Introduction: .......................................................................................................................................................... 3 II. Requirement: ......................................................................................................................................................... 4 III. UI design: ............................................................................................................................................................... 4 IV. Implementation: .................................................................................................................................................... 4

II. Requirement:

The java program that I created helped me solve some of the following problems:

  • I can enter data and edit and delete them easily and understandably
  • I can review the information I have entered before through the program's file reading and writing function

III. UI design:

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 3 main parts: 2 class named Customer.java and Myroom.java, 1 Jframe named TableFrm.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,... ).

▪ 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.

▪ I applied for 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).

▪ getSelectedItem() method returns the currently selected item. ▪ getSize() method returns the size of the rooms list. ▪ getElementAt(int index) method returns the element at the specified index in the rooms list.

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:
  • This code defines a class called TableFrm, which extends the javax.swing.JFrame class. The class contains a few fields such as an ArrayList of Customer objects, a DefaultTableModel object, an integer editedIndex, and a constant FILE_NAME with a value of "DATA.txt".
  • The constructor initializes the ArrayList of customers and the tableModel object. It sets the actionState to ADD. Then it reads data from the file with the name specified by FILE_NAME using a BufferedReader and a FileReader, and creates a new Customer object for each line in the file. The Customer objects are added to the customers ArrayList.
  • This code is an event handler for the "Add" button of a user interface. It first retrieves input data from several text fields and a combo box. Then, it checks if the required input fields are not empty.
  • If they are not empty, the code creates a new Customer object with the input data. If the actionState is ActionState.ADD, it checks if there's no existing customer with the same ID. If the ID already exists, it shows an error message. Otherwise, it adds the new customer to the customers list and displays the new customer's information in the table.
  • If the actionState is ActionState.EDIT, it updates the existing customer's information with the new input data and displays the updated information in the table. It also changes the actionState back to ActionState.ADD and changes the text of the "Add" button to "Insert new". If any of the required input fields are empty, it shows an error message. Finally, it clears the text fields.
  • This code is an event handler for the "Delete" button. When the button is clicked, it will check if there are any customers in the list. If there are, it will get the index of the selected
  • After that, it will clear the data from the customers list and update the table. Finally, it will display a message to inform the user that all data has been deleted. If the user chooses not to delete the data, it will display a message saying that the list is empty.
  • This is a method that handles the "Edit" button's click event. When the user clicks the "Edit" button, this method will be executed.
  • Firstly, the code checks whether there are any customers in the list. If there are no customers in the list, a message box will appear and inform the user that the inputs cannot be blank.
  • If there are customers in the list, the method gets the index of the selected row in the table. If no row is selected, a message box will appear and inform the user to choose a row.
  • If a row is selected, the method retrieves the customer object at that row's index and sets the text fields with the customer's information. Then, it checks the type combobox's items and selects the item that matches the customer's type.
  • The method changes the "Add" button's text to "Update & Save" and sets the action state to "EDIT" so that when the user clicks the "Add" button after making changes, the program will update the customer's information instead of adding a new customer.
  • This code is the event handler for a button that closes the program when clicked. It first displays a confirmation dialog box asking the user if they really want to exit the program. If the user clicks "Yes", the code checks if the customer list is empty.
  • If it is, a message is displayed saying there are no customers. If the customer list is not empty, the code tries to save the customer information to a file.
  • This error occurs when the user does not enter data that is within the range I created. To fix this error, please enter the correct data.
  • This error occurs when the user forgets to select the column to edit, the program will display the message: "Please choose a row"

V. Test case:

Test case Test Action Test Type Results Expect ed Outco me In java class Declare variable Enter correct data Normal The program runs normally The program runs normally Wrong data input Error Error reporting system In java Jframe Read and Write File Right path Normal The system runs normally, the file reading and writing functions are still executed, and the user can still see the previous informa tion display. The system runs normally, the file reading and writing functions are still executed, and the user can still see the previous information display.