






















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 14 May 2022 Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Hồ Ngọc Khánh Student ID GCS Class GCD0901 Assessor name Phạm Thanh Sơn 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 Khanh 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:
I. IMPLEMENT ADT & ALGORITHMS
One aspect of the provider interface for the middleware that is presently being developed is how messages may be transported and processed via layers. Typically, a buffer of queued messages is used for transit, and a stack of messages is used for processing. I need to create these kind of collections for the system. We should create ADT / algorithms for these two structures and develop a sample version in which the message is a string with a maximum length of 250 characters. The demo will show some of these structures' most significant operations. Even if it's only a demo, failures should be handled properly through exceptions, and some tests should be run to ensure that algorithms and operations are valid.
Figure 2 : FLOWCHART FOR STACKPROCESS FUNCTION AND STACKSTART FUNCTION EXPLANATION OF THE SYSTEM 1st. Declare Queue and Stack based on the rebuilt Queue and Stack, also declare strings array 2nd. The first function that the system encounters is the EnterMessage() function. This function just simply reads the line from the console and store it inside a temporary variable 3rd. Declare the variable startTime to start count the time of processing data 4th. The next 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 call for a loop to split all the sentences in that message to elements so it will be easier to handle. At this time there will be four circumstances to happen
First up, I have designed a class called “Buffer” to contain all the messages in the system
Figure 5 : CLASS MYSTACK AND CONSTRUCTOR These three functions take on different tasks. isEmpty would take the job of checking the emptiness of the stack. The push function will make sure that the element adding in won’t overflow the stack. Lastly, the toString will turn the message in the stack into string so the system can easily handle. Figure 6 : ISEMPTY, TOSTRING AND PEEK 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 7 : PUSH FUNCTION OF MYSTACK CLASS 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 8 : POP FUNCTION IN MYSTACK CLASS Now, let’s move on to rebuilding a Queue of my own. Below are declaration of some needed variables and the constructor.
Figure 11 : ENQUEUE FUNCTION IN MYQUEUE CLASS DeQueue function allows the program to remove the message form the front of the Queue and it also runs on O(1). Figure 12 : DEQUEUE FUNCTION IN MYQUEUE CLASS The toString will turn the message in the stack into string so the system can easily handle. Figure 13 : TOSTRING FUNCTION IN MYQUEUE CLASS
Figure 14 : IMPORTED LIBRARIES AND VARIABLES DECLARATION Figure 15 : MAIN FUNCTION Figure 16 : ENTERMESSAGE FUNCTION
Figure 19 : STACKSTART FUNCTION HANDLE ERRORS BY EXCEPTION No program or segment may be regarded finished until the necessary error handling 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 kill 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." This implies that it must
In Java, the catch block is used to manage Exceptions by defining the exception type in the argument. The stated exception must be either a parent class exception or a generated exception type. The best way, however, is to define the created kind of exception. The catch block should only be used after the try block. With a single try block, you may utilize many catch blocks. Figure 20 : TRY CATCH SENTENCE IN POP FUNCTION Figure 21 : THROW ILLEGAL STATE EXCEPTION AT ENSURENONEMPTY FUNCTION
instead of years You can complete these flexible and affordable online learning programs on your own schedule and you will benefit from interactive the system informs to retype the message message went out of bounds and retyping required (Screenshot no.2) 3 Type in messages separated with periods Earn a certificate from a world class university. Build job ready skills to grow your career in months instead of years. You can complete these flexible and affordable online learning programs. Messages will be separated and saved to Queue one by one, the messages will be sent one by one The message couldn’t separate itself and the message was sent fully (Screenshot no.3) Passed 4 Type in message that doesn’t contain anything Firstly, the system will inform that the message goes over 250 characters then the system informs to retype the message The message is sent unsuccessfully with the notification of the message went numb and retyping required (Screenshot no.4) Passed Table 1 : TEST CASES