









































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










































Qualification BTEC Level 5 HND Diploma in Computing
Unit number and title Unit 19: Data Structures and Algorithms
Submission date Date Received 1st submission
Re-submission Date Date Received 2nd submission
Student Name Phan Minh Tiến Student ID GCD
Class GCD1001^ Assessor name Hồ^ Văn Phi
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 Tiến
Grading grid
P 4 P 5 P 6 P 7 M 4 M 5 D3 D
Grade: Assessor Signature: Date:
Internal Verifier’s Comments:
IV Signature:
Figure 1: Flowchart of Main function, Read File message.txt function, and Transfer Message Function
Figure 2: Flowchart for processStack() function and printMessages() function Explanation of the system Firstly, declare Queue and Stack based on the rebuilt Queue and Stack. Secondly, create the file “message.txt” to enter your text. Thirdly, Declare the variable startTime to start count the time of processing data. Fourthly, The function that the system encounters is TransferMessage(). This function will do the job of making sure that the message inputted is totally fine. First up, the function will Read file “message.txt”. Then the function will call for a loop to split all the sentences in message to elements so it will be easier to handle. At this time there will be some situation to happen bellow: The length of the message goes over 250 characters: a new exception will be thrown which is called Index_Out_Of_Bounds_Exception. The system will ask the user to type the message again. There is nothing in the message: a new exception will be thrown and it is called IO_Exception. The system will also ask the user to type the message again. The message that doesn’t meet any above mistakes: that message will be enqueued to the queue and the system will notify that the message has been successfully sent. The last exception where we can’t cover: Illegal-State-Exception.
Figure 4: Interface AbstractQueue
Figure 5: Interface AbstractStack
Next up, I personally built class Queue to implements interface AbstractQueue.. Below are declaration of some needed variables and the constructor.
Figure 6: Class Stack and Constructor
These two functions in Queue class also take different tasks. For the peek function, it will return the element. Next up, we have ensureNonEmpty function, this one actually check on the non-emptiness of the queue.
Figure 7: Peek() and ensureNonEmpty() funtions
enqueuer() function will allow the program to insert new message into the Queue and it runs onO(1).
Next that, I continue create class Stack to implement interface Abstract Class:
Figure 11: Class Stack and Constructor
These four functions take on different tasks. isEmpty() funtion would take the job of checking the emptiness of the stack. The peek function will make sure that the element adding in won’t overflow the stack. The size() method to set up the length for paragraph. Lastly, the toString will return the message in the stack into string so the system can easily handle.
Figure 12: isEmpty(), peek(), size(), toString() function
For the Push function, this is the class that will insert the new message on top of the stack and also this functionality runs on O(1).
Figure 13: Push function in class Stack
For the Pop function, this is the class where the program will remove the top or the most recent message out of the stack and it also runs on O(1).
Figure 14: Pop function in class Stack
Main method: to run program
Figure 15: Main method
Result:
II. Implement error handing and report test results (P5)
1. Handle Errors By Exception No program or segment may be regarded finished until the necessary error handing has been implemented. Unwanted program failures are a disaster – at most, they bring disappointment since program users must redo minutes or hours of effort, but in life-critical programs, even the most minor program fault has the potential to skill someone if not treated appropriately. If a mistake is fatal in the sense that a program cannot reasonably continue, it must be able to “die gracefully”.
Figure 17: NullArgumentException
FileNotFoundException: The exception is thrown when trying to access a file that does not exist in the system
Figure 18: FileNotFoundException
IOException: The IOException is simply an exception that is thrown when an Input/Output error occurs. It is also the base class of such exceptions that occur while reading or accessing files, directories and streams.
Figure 19: IOException
2. Test Program Test Case (No)
Test Description Action test Expected Result Actual Result Status
1 Read file “message.txt” Create file “message.txt” with less than 250 characters. Next, use FileReader() function to declare the file I want read, then use BufferedReader() function to implement read that file.
After done sending message, we can read the message printed right after.
Figure 20 : Actual Result 1
Passed
2 Read file “message.txt” with over 250 characters
Create file “message.txt” with over 250 characters. Next, implement the same test case 1 and run program.
The system will display an notification “The message characters must be less than 250 character!!! Please retype” and exit program.
Figure 21 : Actual Result 2
Passed
3 Read file “message.txt” doesn’t contain anything
Create file “message.txt” with doesn’t contain anything. Then run program
The system will display an notification “You haven’t typed anything yet! Please retype must not be null”
Figure 22 : Actual Result 3
Passed
4 Read file “message.txt” separate with period
Create file “message.txt” separated with period. Then run program
The system will display message with the different line by period
Figure 23 : Actual Result 4
Passed
5 Try read file “message.txt” from the unknow path.
Declare a path of file “message.txt” don’t have system. Then run program
The system will display an notification “Find Not Find”
Figure 24 : Actual Result 5
Passed