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

Assignment PROG191 Java Programming Distinction

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 (6.78 MB, 160 trang )

ASSIGNMENT 1 FRONT SHEET
Qualification

BTEC Level 5 HND Diploma in Computing

Unit number and title
Submission date

23/06/2023

Re-submission Date

Date Received 1st submission

23/06/2023

Date Received 2nd submission

Student Name

Tran Duc Long

Student ID

GCH210562

Class

GCH1106

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
Grading grid
Grade (0-10)
1.1

Page 1 of 159


❒ Summative Feedback:

❒ Resubmission Feedback:

2.1

Grade:
IV Signature:

Assessor Signature:

Date:

Page 2 of 159



Table of Contents
I.

Introduction ....................................................................................................................................................................................... 11

II.

Requirement ...................................................................................................................................................................................... 11

III. UI design ............................................................................................................................................................................................ 13
1.

Login and Register.......................................................................................................................................................................... 13

2.

Wireframe Homepage ................................................................................................................................................................... 13
a.

Subject ........................................................................................................................................................................................ 14

b.

Student ....................................................................................................................................................................................... 14

c.

Register....................................................................................................................................................................................... 15

d.


Class division .............................................................................................................................................................................. 16

IV.

Implementation ............................................................................................................................................................................. 17

1.

Program structure .......................................................................................................................................................................... 17

2.

Classes ............................................................................................................................................................................................ 19
2.1.

Package exception .................................................................................................................................................................. 19

a.

InvalidPersonIdException ........................................................................................................................................................... 20

b.

InvalidStudentIdException ......................................................................................................................................................... 21

c.

InvalidNameException ............................................................................................................................................................... 22


d.

InvalidPhoneNumberException ................................................................................................................................................. 23

e.

InvalidEmailException ................................................................................................................................................................ 24

f.

InvalidDateOfBirthException...................................................................................................................................................... 26

g.

InvalidPasswordException.......................................................................................................................................................... 27
Page 3 of 159


2.2.

Package model ........................................................................................................................................................................ 28

a.

Account ...................................................................................................................................................................................... 28

b.

Subject ........................................................................................................................................................................................ 31


c.

Person......................................................................................................................................................................................... 34

d.

Student ....................................................................................................................................................................................... 40

e.

Registering .................................................................................................................................................................................. 43

f.

Course......................................................................................................................................................................................... 45

2.3.

Package controller.sort ........................................................................................................................................................... 46

a.

SortRegisteringByRegisterTime .................................................................................................................................................. 47

b.

SortRegisteringByStudentName................................................................................................................................................. 47

c.


SortStudentByName ................................................................................................................................................................... 48

d.

SortStudentByStudentIdASC ...................................................................................................................................................... 49

e.

SortSubjectByNumOfLesson ...................................................................................................................................................... 49

f.

sortSubjectByName .................................................................................................................................................................... 50

2.4.

Package controller .................................................................................................................................................................. 51

2.4.1

InforFilter ............................................................................................................................................................................ 51

2.4.2

InforFilterImp ...................................................................................................................................................................... 51

2.4.3

DataController .................................................................................................................................................................... 56


2.4.4

DataControllerImp .............................................................................................................................................................. 57

a.

Methods of reading and writing data to file .............................................................................................................................. 57

b.

Methods of reading and writing data to mySQL in Xampp........................................................................................................ 59
Page 4 of 159


c.

Methods sort by criteria............................................................................................................................................................. 62

d.

Methods createCourse ............................................................................................................................................................... 64

e.

Methods search by criteria ........................................................................................................................................................ 65

2.5.

Package view .......................................................................................................................................................................... 68


a.

LoginFrm ..................................................................................................................................................................................... 69

b.

SignUpFrm .................................................................................................................................................................................. 71

c.

HomeFrm.................................................................................................................................................................................... 74

d.

AddSubjectDialog ....................................................................................................................................................................... 89

e.

AddStudentDialog ...................................................................................................................................................................... 91

f.

AddRegisterDialog ...................................................................................................................................................................... 93

g.

EditStudentDialog....................................................................................................................................................................... 96

h.


EditSubjectDialog ....................................................................................................................................................................... 98

3.

Important algorithms ................................................................................................................................................................... 100

4.

How to handle errors ................................................................................................................................................................... 103

V.

4.1.

Error when user entered wrong input data ......................................................................................................................... 103

4.2.

Error when saving file ........................................................................................................................................................... 105

4.3.

Error when connect xampp .................................................................................................................................................. 107

Test .................................................................................................................................................................................................. 108
1.

Test Junit ...................................................................................................................................................................................... 108
a.


DataControllerImpTest ............................................................................................................................................................. 108

b.

InforFilterImpTest .................................................................................................................................................................... 114
Page 5 of 159


2.

Test plan ....................................................................................................................................................................................... 116

3.

Testing result................................................................................................................................................................................ 146

4.

Solution ........................................................................................................................................................................................ 146

VI.

Screenshots of running program ................................................................................................................................................. 148

1.

Sign up .......................................................................................................................................................................................... 148

2.


Login ............................................................................................................................................................................................. 148

3.

Tab subject ................................................................................................................................................................................... 149

4.

5.

3.1.

Add subject ........................................................................................................................................................................... 150

3.2.

Edit subject ........................................................................................................................................................................... 151

Tab student .................................................................................................................................................................................. 152
4.1.

Add student .......................................................................................................................................................................... 153

4.2.

Edit student .......................................................................................................................................................................... 154

Tab register .................................................................................................................................................................................. 155
5.1.


6.
VII.

Add register .......................................................................................................................................................................... 156

Tab class division .......................................................................................................................................................................... 157
Conclusion .................................................................................................................................................................................... 158

Page 6 of 159


Table of Figures
Figure 1: Wireframe Sign up and login ........................................................................................................................................................................ 13
Figure 2: Wirfeframe tab Subject................................................................................................................................................................................. 14
Figure 3: Wireframe tab student ................................................................................................................................................................................. 15
Figure 4: Wireframe tab register ................................................................................................................................................................................. 16
Figure 5: Wireframe tab Class division ........................................................................................................................................................................ 17
Figure 6: My program structure................................................................................................................................................................................... 19
Figure 7: Class InvalidPersonIdException..................................................................................................................................................................... 20
Figure 8: Class InvalidStudentIdException ................................................................................................................................................................... 21
Figure 9: Class InvalidNameException ......................................................................................................................................................................... 22
Figure 10: Class InvalidPhoneNumberException ......................................................................................................................................................... 23
Figure 11: Class InvalidEmailException: ....................................................................................................................................................................... 25
Figure 12: Class InvalidDateOfBirthException ............................................................................................................................................................. 26
Figure 13: Class InvalidPasswordException ................................................................................................................................................................. 27
Figure 14: Class account in model package ................................................................................................................................................................. 31
Figure 15: Class Subject ............................................................................................................................................................................................... 34
Figure 16: Class Person ................................................................................................................................................................................................ 40
Figure 17: Class Student ............................................................................................................................................................................................... 43
Figure 18: Class Registering ......................................................................................................................................................................................... 45

Figure 19: Class Course ................................................................................................................................................................................................ 46
Figure 20: Class SortRegisteringByRegisterTimeEL ...................................................................................................................................................... 47
Figure 21: Class SortRegisteringByRegisterTimeEL ...................................................................................................................................................... 47
Figure 22: Class SortRegisteringByStudentNameAZ .................................................................................................................................................... 48
Figure 23: Class SortRegisteringByStudentNameZA .................................................................................................................................................... 48
Figure 24: Class SortStudentByNameASC .................................................................................................................................................................... 48
Figure 25: Class SortStudentByNameDESC .................................................................................................................................................................. 49
Figure 26: Class SortStudentByStudentIdASC .............................................................................................................................................................. 49
Figure 27: Class sortSubjectByNumOfLessonASC ........................................................................................................................................................ 50
Figure 28: Class sortSubjectByNumOfLessonDESC ...................................................................................................................................................... 50
Page 7 of 159


Figure 29: Class sortSubjectByNameASC ..................................................................................................................................................................... 50
Figure 30: Class sortSubjectByNameDESC ................................................................................................................................................................... 51
Figure 31: Interface InforFilter ..................................................................................................................................................................................... 51
Figure 32: Method isStudentIdValid ............................................................................................................................................................................ 52
Figure 33: Method isPersonIdValid .............................................................................................................................................................................. 52
Figure 34: Method isNameValid .................................................................................................................................................................................. 53
Figure 35: Method isEmailValid ................................................................................................................................................................................... 53
Figure 36: Method isPhoneNumberValid .................................................................................................................................................................... 54
Figure 37: Method isDateOfBirthValid......................................................................................................................................................................... 54
Figure 38: Method isPasswordValid ............................................................................................................................................................................ 55
Figure 39: Interface DataController ............................................................................................................................................................................. 57
Figure 40: Method writeToFile .................................................................................................................................................................................... 58
Figure 41: Method readDataFromFile ......................................................................................................................................................................... 59
Figure 42: Method connect xampp with netbeans...................................................................................................................................................... 60
Figure 43: Method login............................................................................................................................................................................................... 61
Figure 44: Method Register account ........................................................................................................................................................................... 62
Figure 45: Methods sort by critiea of Subject .............................................................................................................................................................. 63

Figure 46: Methods sort by critiea of Student ............................................................................................................................................................. 63
Figure 47: Method sort by critiea of Registering ......................................................................................................................................................... 64
Figure 48: Method createCourse ................................................................................................................................................................................. 65
Figure 49: Methods search by critiea of Subject ......................................................................................................................................................... 66
Figure 50: Method search by critiea of Student .......................................................................................................................................................... 67
Figure 51: Method search by critiea of Registering ..................................................................................................................................................... 68
Figure 52: Method addActionListener ......................................................................................................................................................................... 69
Figure 53: Method actionPerformed ........................................................................................................................................................................... 69
Figure 54: Method loadData ........................................................................................................................................................................................ 70
Figure 55: Method loginSystem ................................................................................................................................................................................... 71
Figure 56: Methods catch event .................................................................................................................................................................................. 72
Figure 57: Method registerAccounts ........................................................................................................................................................................... 73
Figure 58: Constructor in HomeFrm ............................................................................................................................................................................ 74
Page 8 of 159


Figure 59: Methods catch events in HomeFrm............................................................................................................................................................ 77
Figure 60: Method loadData ........................................................................................................................................................................................ 77
Figure 61: Method showData ...................................................................................................................................................................................... 78
Figure 62: Methods to display the Add forms ............................................................................................................................................................. 80
Figure 63: Methods add callback object ...................................................................................................................................................................... 81
Figure 64: Methods to display forms Update .............................................................................................................................................................. 81
Figure 65: Methods edit callback object ...................................................................................................................................................................... 82
Figure 66: Methods remove data in tables .................................................................................................................................................................. 83
Figure 67: Methods sorting data by critiea .................................................................................................................................................................. 84
Figure 68: Methods refresh data in tables................................................................................................................................................................... 85
Figure 69: Methods search data by critiea .................................................................................................................................................................. 89
Figure 70: Methods AddSubjectDialog ........................................................................................................................................................................ 89
Figure 71: Method ClearInputData .............................................................................................................................................................................. 90
Figure 72: Method addNewSubject ............................................................................................................................................................................. 90

Figure 73: Constructors of AddStudentDialog form .................................................................................................................................................... 91
Figure 74: Method addNewStudent ............................................................................................................................................................................ 93
Figure 75: Constructors of addRegisterDialog form .................................................................................................................................................... 94
Figure 76: Method searchSubject ................................................................................................................................................................................ 95
Figure 77: Method searchStudent ............................................................................................................................................................................... 95
Figure 78: Method addNewRegister ............................................................................................................................................................................ 96
Figure 79: Method editStudent ................................................................................................................................................................................... 98
Figure 80: method showData....................................................................................................................................................................................... 99
Figure 81: Method editSubject .................................................................................................................................................................................... 99
Figure 82: Method searchSubjectByName ................................................................................................................................................................ 100
Figure 83: Method searchSubjectByLessonRange ..................................................................................................................................................... 102
Figure 84: Validate process Sign Up account ............................................................................................................................................................. 103
Figure 85: Input data of Student ................................................................................................................................................................................ 104
Figure 86: Process write data to file .......................................................................................................................................................................... 105
Figure 87: Process read data from file ....................................................................................................................................................................... 106
Figure 88: Process connect netbeans to xampp ........................................................................................................................................................ 107
Page 9 of 159


Figure 89: Contructor Class test DataControllerImpTest ........................................................................................................................................... 109
Figure 90: Methods to test methods sort and search in DataControllerImp class .................................................................................................... 113
Figure 91: Result test methods in class DataControllerImp by Junit ......................................................................................................................... 114
Figure 92: Contructor Class test InforFilterImpTest................................................................................................................................................... 114
Figure 93: Methods to test validate data in InforFilterImp Class .............................................................................................................................. 116
Figure 94: Result test methods in class InforFilterImp by Junit ................................................................................................................................. 116
Figure 95: Edit code method isNameValid................................................................................................................................................................. 147
Figure 96: Final test results ........................................................................................................................................................................................ 147
Figure 97: Sign up form .............................................................................................................................................................................................. 148
Figure 98: Login form ................................................................................................................................................................................................. 149
Figure 99: Screenshot of subject tab ......................................................................................................................................................................... 150

Figure 100: Screenshot of add subject....................................................................................................................................................................... 151
Figure 101: Screenshot of edit subject ...................................................................................................................................................................... 152
Figure 102: Screenshot of student tab....................................................................................................................................................................... 153
Figure 103: Screenshot of add student ...................................................................................................................................................................... 154
Figure 104: Screenshot of edit student...................................................................................................................................................................... 155
Figure 105: Screenshot of Register tab ...................................................................................................................................................................... 156
Figure 106: Screenshot of add a new Register .......................................................................................................................................................... 157
Figure 107: Screenshot of class division tab .............................................................................................................................................................. 158

Page 10 of 159


I.

Introduction
I was tasked with developing an app to address a problem faced by small businesses. Specifically, the app aims to assist
teachers in effectively managing students and subjects of Greenwich in a straightforward and user-friendly manner. By
doing so, it enables them to organize classes for students based on individual subjects, thus resolving the challenges of
providing up-to-date information on subjects and class schedules to students. Consequently, I have created a compact
project named "Course Enrollment Management System." In this program, I employ a graphical user interface that
incorporates the basic functionalities of Create, Read, Update, and Delete. Additionally, I have implemented advanced
features like search and sort to enhance the application's functionality. To store and retrieve data, I utilize both file
operations and a MySQL database. To ensure a smooth user experience, I have implemented data validation techniques
that generate custom exceptions to handle errors. Lastly, I have employed JUnit Test to thoroughly examine all the
primary functions of the registering course management program for Greenwich Viet Nam.

II. Requirement
Based on the problem statement provided earlier, the key features of my project are as follows:
• The application must possess an intuitive and user-friendly interface design.
• Users should be able to input information conveniently through the use of forms.

Register
• User can register an account with Email and Password. (Email must have the extension @fpt.edu.vn).
Login
• User login with registered user information
Home
• In the main interface of the application I divided into 4 tabs: Subject, Student, Register and Class Division.
a. Tab Subjects
o The program allows adding Subjects to the table.
o The program allows users to view all Subjects information that has been added to the table.
o The program allows users to update all information (except ID) of any Subjects.
Page 11 of 159


o The program allows users to delete all fields on the form that they have filled out because of incorrect
input to re-fill.
o The program allows users to search for subjects information by approximate name.
o The program allows users to search for subject information by number of lessons.
o The program allows users to sort subjects by name from a-z and z-a.
o The program allows users to sort subjects by number of lesson in ASC order and DESC order.
b. Tab Students
o The program allows adding Students to the table.
o The program allows users to view all Students information that has been added to the table.
o The program allows users to update all information (except ID) of any Students.
o The program allows users to delete all fields on the form that they have filled out because of incorrect
input to re-fill.
o The program allows users to search for students information by approximate name.
o The program allows users to search for students information by id.
o The program allows users to search for students information by major.
o The program allows users to sort students by name from a-z and z-a.
o The program allows users to sort subjects by id.

c. Tab Registerings
o The program allows adding Registerings to the table.
o The program allows users to view all Registerings information that has been added to the table.
o The program allows users to update all information (except ID) of any Registerings.
o The program allows users to delete all fields on the form that they have filled out because of incorrect
input to re-fill.
o The program allows users to search for Registerings information by approximate name.
o The program allows users to search for Registerings information by Student's name.
o The program allows users to search for Registerings information by subscription time.
Page 12 of 159


o The program allows users to sort Registerings by student's name from a-z and z-a.
o The program allows users to sort Registerings by Early-late and Late-early registration time.
d. Tab Class division
o The program allows to create classes with data taken from the subject registration table, student
information and subject information.
In order to fulfill the requirements mentioned above, I have decided to utilize Netbean tool as the development platform
and employ the Java language along with Java Swing. This choice enables me to create high-quality solutions that align
with the school's standards.

III. UI design
1. Login and Register
Users must register an account by email with the extension @fpt.edu.vn. After registration is complete, users can log
in with the previously registered account to access the system.

Figure 1: Wireframe Sign up and login

2. Wireframe Homepage
Page 13 of 159



a. Subject
After entering the system, the user will see the subject management section:

Figure 2: Wirfeframe tab Subject

b. Student
The student tab is located next to the Subject section. When the user clicks on the student item, program will
switch to the student management form.

Page 14 of 159


Figure 3: Wireframe tab student

c. Register
The register tab is located next to the Student section. When the user clicks on the register item, program will
switch to the register management form.

Page 15 of 159


Figure 4: Wireframe tab register

d. Class division
The Class division tab is located next to the Register section. When the user clicks on the Class division item,
program will switch to the create Course form.

Page 16 of 159



Figure 5: Wireframe tab Class division

IV. Implementation
1. Program structure
The diagram provided illustrates the architecture of my Java application developed with the assistance of netbean
coding tools. I have employed the MVC (Model-View-Controller) pattern to ensure efficient code management and
establish a logical flow of data within the program. This approach enables a cohesive execution of the program's
functionalities.
Page 17 of 159


I divided the program into 5 main packages: model, view, controller, controller.sort and exception. The package
model will contain classes that display data such as account, course, person, student, registering, and subject.
Package View will be the place to display the user interface including the main form of the program. The Package
Controller will be the place to control the flow of data, like the brain of the program, including the interfaces and the
classes that implement them. Package controller.sort which contains sort classes according to each criterion related
to subject, student, register. Package exception is used to make exceptions defined by myself to validate the input
data of the program in accordance with the desired form of FPT.
By adopting the segregation of code across the three levels, the process of dividing and organizing the logic of web
applications becomes remarkably straightforward, especially for managing large-scale projects involving sizable
developer teams. The primary advantage of employing such coding practices is the facilitation of rapid identification
of specific code sections and seamless incorporation of new functionalities.
The utilization of the MVC methodology greatly simplifies the modification of the entire application. In the MVC
pattern, the addition or updating of new views is streamlined due to the independence of each section.
Consequently, any changes made to a particular section of the application do not impact the entire architecture. This
aspect enhances the flexibility and scalability of my application, as it enables seamless adaptation and expansion
without disrupting the overall structure.


Page 18 of 159


Figure 6: My program structure

2. Classes
The successful production of a final product relies on how different classes are organized and how each class
approaches a task. Here is a list of all the classes included in the program.

2.1.

Package exception
Page 19 of 159


a. InvalidPersonIdException

Figure 7: Class InvalidPersonIdException

The above code defines a custom class named InvalidPersonIdException which extends from the Exception
class in Java. This class was created to represent a special exception to be used when an error occurs with an
invalid person ID.
The InvalidPersonIdException class has two properties: invalidId: A string (String) representing an invalid
person ID.
The InvalidPersonIdException class provides the following methods:
InvalidPersonIdException(): Default constructor with no parameters.
InvalidPersonIdException(String invalidId, String message): The constructor takes two parameters, one is
invalidId representing the invalid person ID and the other is a message representing the message of the
exception.
getInvalidId(): The method returns the value of the invalidId property.

setInvalidId(String invalidId): The method that assigns a value to the invalidId property.
Page 20 of 159



×