1. Homepage
  2. Programming
  3. [2022] CPT105 Introduction to Programming in Java 2021-2022 S1 - Resit Coursework Task Sheet

[2022] CPT105 Introduction to Programming in Java 2021-2022 S1 - Resit Coursework Task Sheet

Engage in a Conversation
CPT105Introduction to Programming in JavaXJTLUData Encapsulation

CPT105 Introduction to Programming in Java 2021-2022 S1
Overview CourseNana.COM

Part A CourseNana.COM

In Part A, you are required to write a GUI program to simulate data encapsulation when we transfer data via the Internet. You should follow the description to produce the correct output. It is further divided into two parts: Part A.1 and A.2. CourseNana.COM

CW3 Part A will contribute to 35% of the total marks. CourseNana.COM

Part A.1 DataPacket (12 marks) CourseNana.COM

We usually transfer encrypted data packets via the Internet to protect the privacy of original data. Usually, an encrypted data packet is composed of several components: the frame header, frame tail, length of data and encrypted data. Table 1 below shows the detailed packet structure used in the question. CourseNana.COM

Table 1. Packet structure CourseNana.COM

Header Data length Encrypted data segment Tail
2 Bytes 1 Byte N Bytes 2 Bytes CourseNana.COM

In Table 1, we use 2 hexadecimal constants of “AAAA” and “BBBB” to represent the header and tail of a data packet (Header and Tail columns), respectively, one byte to represent the length of the encrypted data. We should encrypt the original data and encapsulate the encrypted data into the data segment and convert the data packet to a hexadecimal string before we send the data via the Internet. The procedure of the data encapsulation is as follows: CourseNana.COM

(1) Encrypt the data string into an encrypted string.
(2) Calculate the length of the encrypted string.
(3) Convert encrypted string into a hexadecimal value.
(4) Combine the header, data length, encrypted data and tail into a data packet. CourseNana.COM

For example, before we send a string “123” to a remote user via the Internet. The string should be encrypted and encapsulated into a data packet of a hexadecimal string “AAAA0c44464567552f507a6e4f513dBBBB”. “AAAA” and “BBBB” are the header and tail of the data packet, “0c” represents the length of encrypted data (12 bytes), “44464567552f507a6e4f513d” is the hexadecimal string of each character in the encrypted data “DFEgU/PznOQ=”. We defined a class “Encryption” to help you encrypt or decrypt strings as follows: CourseNana.COM

2 Please follow the steps below to complete the task:
(1) Create an empty java project. The project name should be “Resit_1”. (2) Create a class “Encryption” in your project. CourseNana.COM

  1. (a)  Copy the code from the figure above into your Encryption class;
  2. (b)  Change the encryption key to your student id.

(3) Create CourseNana.COM

  1. (a)  Defineamethod“strToHex(Stringstr)”toconvertacommonstringinto

a hexadecimal string. For example, convert a string “123A” to CourseNana.COM

“31323341”. CourseNana.COM

  1. (b)  Define a method “convertToDataPacket(String data)”, which can

encrypt a string into a new encrypted string and encapsulate it into a data packet and return a hexadecimal string, as Table 1 shows. For example, encrypt a string “123” into a data packet string “AAAA0c 44464567552f507a6e4f513dBBBB”. CourseNana.COM

  1. (c)  Define a method “getDataFromDataPacket(String hexData)”, which can retrieve the original data from a hexadecimal string of a data packet. The method should check the header and tail of the packet and the length of the data. For example, retrieve the original data string “123” from the data packet “AAAA0c44464567552f507a6e4f5 13dBBBB”

a class “DataPacket”. CourseNana.COM

(4) Create
(a) Create a frame window as the following; CourseNana.COM

a class “Q1” and achieve the following functions in its main method. CourseNana.COM

(b) Create a DataPacket object in the main method;
(c) When users click “Data to packet” button, the string in the raw data CourseNana.COM

text field can be encrypted and showed in the encrypted data text field. The encrypted data can be encapsulated into a data packet string, and the data packet is shown in the data packet text field; CourseNana.COM

(d) When users click “Packet to data” button, it can retrieve the encrypted and original data strings from the data packet field and show them in the raw data and encrypted data text fields, respectively. CourseNana.COM

Part A.2 MultiDataPacket (23 marks) CourseNana.COM

Sometimes, we need to transfer several data within one data packet to improve data transmission efficiency. For example, if we send three strings of “ABC”, “EFG” and “HIJ” in one data packet, the hexadecimal value of the data packet is “AAAA0c685279554936796637696b3dBBBBAAAA0c61427a616c76474133366b3dBB BBAAAA0c5861346a4970775755756b3dBBBB”. The sub string of “AAAA0c68527955 4936796637696b3dBBBB” is the hexadecimal data of the first encrypted string “ABC”. The sub strings of “AAAA0c61427a616c76474133366b3dBBBB” and “AAAA0c5861346a4970775755756b3dBBBB” are the hexadecimal data for encrypted strings of “EFG” and “HIJ”, respectively. In addition, you should check the validation of the data packet before we retrieve data from it. If the data packet is not valid, you should throw an exception. Please follow the steps below to complete the task. CourseNana.COM

(1) Create an exception class “MyException”, which is inherited from “Exception”. CourseNana.COM

  1. (a)  Create a constructor “MyException (String message)” to create an

exception object with a string of the exception message. CourseNana.COM

  1. (b)  Override the method “toString()” to return the message string.

(2) Create a subclass “MultiDataPacket” based on the base class “DataPacket”. CourseNana.COM

  1. (a)  Create an overloading method “String[] strToHex(String[] str)”, which can convert an array of common strings to an array of hexadecimal

strings. CourseNana.COM

  1. (b)  Create an overloading method “String convertToHexDataPacket

(String[] data)”, which can convert an array of common strings to a MultiDataPacket with a single hexadecimal string. CourseNana.COM

4 CourseNana.COM

(c) Create a new method “String[] getMultiDataFromHexDataPacket (String hexData)” to retrieve and return an array of strings from the MultiDataPacket string “hexData”. The method should validate the header, tail and length for each data packet in the string “hexData” and throw a “MyException” exception if any validation is failed. CourseNana.COM

(3) Create a class “ImgePanel”, which is inherited from class “JPanel”.
a. Define a public constructor to create an ImagePanel object with an CourseNana.COM

image file name.
b. Override the method “paintComponent (Graphics g)” to set a CourseNana.COM

background image for the ImagePanel object.
(4) Create a class “Q2” and achieve the following functions in its main method. CourseNana.COM

  1. (a)  Create a frame window as below;

You should list your student Id on the top of the window, set a background image for the frame window, and set labels’ font size to 15 and font color to red. You can use any image you like. CourseNana.COM

  1. (b)  Create a MultiDataPacket object in the main method;
  2. (c)  CreateanImagePanelobjectwithabackgroundimageandaddittothe

Frame window as the main container of other components. CourseNana.COM

  1. (d)  Users can input strings into the first 3 text fields ( raw data 1~raw data 3). When users click the “Convert to multi packet” button, strings in the 3 text fields can be encrypted and encapsulated into a hexadecimal

string and shown in the “multi data packet” text field. CourseNana.COM

  1. (e)  When “Retrive data” button is clicked, users can retrieve all the separate data from the “multi data packet” text field and show them in

the first 3 text fields (Raw data 1~Raw data 3), respectively. CourseNana.COM

  1. (f)  You should use a message dialogue to show any exceptions raised in

your program. Below is an example for your reference. CourseNana.COM

Get in Touch with Our Experts

WeChat WeChat
Whatsapp WhatsApp
CPT105代写,Introduction to Programming in Java代写,XJTLU代写,Data Encapsulation代写,CPT105代编,Introduction to Programming in Java代编,XJTLU代编,Data Encapsulation代编,CPT105代考,Introduction to Programming in Java代考,XJTLU代考,Data Encapsulation代考,CPT105help,Introduction to Programming in Javahelp,XJTLUhelp,Data Encapsulationhelp,CPT105作业代写,Introduction to Programming in Java作业代写,XJTLU作业代写,Data Encapsulation作业代写,CPT105编程代写,Introduction to Programming in Java编程代写,XJTLU编程代写,Data Encapsulation编程代写,CPT105programming help,Introduction to Programming in Javaprogramming help,XJTLUprogramming help,Data Encapsulationprogramming help,CPT105assignment help,Introduction to Programming in Javaassignment help,XJTLUassignment help,Data Encapsulationassignment help,CPT105solution,Introduction to Programming in Javasolution,XJTLUsolution,Data Encapsulationsolution,