COSC 180 Assign 3 Due Date Nov 5, 2021 Place all work in a package called cstAsssign3. Additionally, all methods should be included as part of a class Assign3Methods. There will be a unit test file...

1 answer below »
this should pass the junit testing code


COSC 180 Assign 3 Due Date Nov 5, 2021 Place all work in a package called cstAsssign3. Additionally, all methods should be included as part of a class Assign3Methods. There will be a unit test file made available to you in the handout drive by Friday Note: For this assignment you are not allowed to use the built in Java class Array (or associated Java collection classes) as part of your solution for any of these questions. Your Method names must be the same as given here. Question 1: Write a method decToHex that will take in a integer parameter and return that value as a hex string (starting with “0x”). For example, if the method was given the value 528 it would return “0x210”. public static String decToHex(int nVal) [5 Marks] Question 2: Write a method genHexArray that will take in an array of integers and return an array of strings that corresponds to the hex representation of all the numbers in the integer array. For example, if provided with the array [ 12, 33, 51, 528 ] this routine would return an array consisting of the strings [“0xC”, “0x21”, “0x33”,”0x210”]. public static String[] genHexArray(int [] naVals) [10 Marks] Question 3: Write a method arrayUnion which will take two arrays (with unique values) as parameters and returns an array composed of entries which exist in both arrays. For example, given the following array definitions int[] naOne = {3, 19, 22, 14, 7, 8 ,9 }; int[] naTwo = { 12, 7, 2, 8, 4 }; The resultant array would hold the following entries {7, 8}. Your method should return null if there are no common elements. Public static int[] arrayUnion(int[] naOne, int[] naTwo) [10 Marks] Question 4: My football number in high school was 21 – so let’s invent a numbering system with a base of 21; we will call it 0b. The numbering system will be the same as the hex system up to a number 15 but then use a different system after that: The following table will illustrate this: Dec 0b Dec Ob Dec Ob Dec Ob 0 0 1 1 2 2 3 3 3 4 5 5 6 6 7 7 8 8 9 9 10 A 11 B 12 C 13 D 14 E 15 F 16 : 17 ; 18< 19="20"> 21 ? You are required to write a method decTo0b that will convert an integer value to ob value according to the values listed in the previous table, so for example if you input a value of 17 you would get a value of “Ob;” while if you input a value of 44 you would get “0b22”, and if you input 460 you would get ‘0b10=”. public static String decToOb(int nVal) [10 Marks] Question 5: In cryptography there exists the concept of a “One-time Numbering pad”. These are pads that are generated using a completely random technique (like street noises) and then paired with a single message. In theory the messages that are sent will be completely unbreakable as “men in the middle” would have nothing to compare against. Such pads put randomly generated characters into positions in the pad that correspond to positions in the alphabet. For example, the first random character that you generate would correspond to ‘a’ while the next random character would correspond to ‘b’. You are required to write a method getRandomPad that will return a string 26 characters long consisting of randomly generated characters in the range ‘a’ to ‘z’. There can be no duplicate characters (think of just taking lower case characters and randomly shuffling them into different positions). public static String genRandomPad() Note: I ran my solution three times and came up with: ngwplsehyvcdkfjiaqxmobuztr lhaqndpfkyxoswcmvrgejbuizt tovscbgxjwufphzyrkelidqman [10 Marks] Question 6: Write a method genPads that will take an integer argument and return a String array of that size, with each entry in that String array consisting of a unique one-time pad. public static String[] genPads(int nSize) [10 Marks] Question 7: Write a method encryptFromPads() that will take in a plain text message and an array of one-time pads and return an encrypted message which is generated using the array of time pads in the following fashion: · The first character is encrypted using the first one-time pad entry (find the corresponding letter pos in the one-time pad that corresponds to the letter position of the current character in the plain text message). · The Second is encrypted using the second one- time pad entry. · Continue this process for all characters, wrapping back to the first entry when you have used the last pad in the list. You may assume that the plain text message consists only of lower-case letters and spaces. Spaces are to be written through (don’t advance the one-time pad counter) to the encrypted message. public static String encryptFromPad(String sMessage, String[] saPads) [15 Marks] Question 8: Write am method decryptFromPad that will take in a String that was encrypted using the above mentioned encryptFromPads method and the same array of one-time pad strings and proceed to decrypt that message. public static String decryptFromPad(String sMessage, String[] saPads) [10 Marks] · Question 9: Write a method getOddValues that will take an integer array as an argument and return a new integer array that is composed of only odd values, sorted in descending order, taken from the original array. For example, if given the following array int[] naTest1 = { 17, 4, 12, 11, 3, 14, 7 }; The method would return the following array: {17, 11, 7, 3} The method signature for this class will be: public static int[] getOddValues(int[] naTest) [10 Marks] Question 10: Write a method insertAtPoint that given an int array, a new value, and a position indicator will return a new array which is a copy of the old array except that the new value is inserted at the given position , shifting all elements (including the replaced value) one back in the array (no elements should be lost). The method signature for this question is: public static int[] insertAtPoint(int[] aVals, int aValue, int nPos) [10 Marks] Question 11: Write a method sortRows that will take as an argument a 2-dimensional array and sort all the given rows in the 2-d array ascending order. 2 11 19 3 14 18 2 5 21 The following illustrates what I want: 19 2 11 14 18 3 21 2 5 The method signature for this class is as follows: public static void sortRows(int[][] naVals) [10 Marks] Question 12: Write a method addColumn that will take in as arguments a two-dimensional array and an array which is supposed to represent the new entries in a column. If the size of the array does not equal the number of rows in the 2-d array , then the method will do nothing and return false. Otherwise, the entries will be added as a new column to the 2-d array. The following diagram will demonstrate what I want: 14 2 1 19 19 21 3 2 6 8 9 4 14 2 1 19 21 3 6 8 9 19 2 4 The method signature for this question will be: public static boolean addColumn(int[][] na2D, int[] naCol) [10 Marks] Question 13: Write a method covertTo1D that will take in a 2-dimensional array and covert the values into a 1-dimensional array (go row by row). The following diagram will show what I want: 2 19 12 3 21 5 2 19 12 3 21 5 The method Signature for this class will be public static int[] convertTo1D(int[][] naVals) [10 Marks] Question 14: Write a method sort2D which will take in a reference to a regular 2-dimensional array and sort that array (smallest element at (0,0), largest at (RowSize -1, ColSize -1). The following diagram will illustrate what I want 2 19 12 3 21 5 2 3 5 12 19 21 The method signature for this is: public static void sort2D(int[][] naVals) [15 Marks]
Answered 2 days AfterNov 11, 2021

Answer To: COSC 180 Assign 3 Due Date Nov 5, 2021 Place all work in a package called cstAsssign3. Additionally,...

Shubham Kumar answered on Nov 14 2021
114 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here