Question: For this problem set, you will submit a single java file named Homework.java . You are supposed to add the functions described below to your

For this problem set, you will submit a single java file named Homework.java. You are supposed to add the functions described below to your Homework class. The functional signatures of the functions you create must exactly match the signatures in the problem titles. You are not allowed to use any 3rd party libraries in the homework assignment nor are you allowed to use any dependencies from the java.util package besides the Pattern Class. When you hava completed your homework, upload the Homework.java file to Grader Than. All tests will timeout and fail if your code takes longer than 10 seconds to complete.

 

privateFunction()

This is a private non-static function that takes no arguments and returns an integer.

You don't need to put any code in this function, you may leave the function's code empty. Don't overthink this problem. This is to test your knowledge on how to create a non-static private function.

Arguments:

returns int - You may choose any integer you would like.

protectedFunction(String, int)

This is a protected non-static function that takes a String and an int as its arguments and returns nothing.

You don't need to put any code in this function, you may leave the function's code empty. Don't overthink this problem. This is to test your knowledge on how to create a non-static protected function.

Arguments:

String text - An string

String int - An integer

countOccurrences(String[], String)

This is a public static function that takes a String[] and a string for the parameters and returns an int.

This function should count the number of times a given pattern (the second parameter) is found within each string in an array of strings (first parameter). Then the function should return the total number of occurrences.

Arguments:

String[] array - An array containing at least one string

String pattern - A string containing at least one character.

returns int - The number of times the pattern is found in the strings in the array.

Example:

array = ["aba", "ckel", "kealska"] pattern = "a" output = 4

mergeAndRemove(int[], int[])

This is a public static function that takes a int[] and int[] for the parameters and returns an int[].

Given two arrays of integers. Your job is to combine them into a single array and remove any duplicates, finally return the merged array.

Arguments:

int[] array_1 - An array of integers

int[] array_2 - An array of integers

returns int[] - An array of integers containing the unique values from both array_1 and array_2

Example:

array_1 = [1,2,3] array_2 = [2,3,4] output = [1,2,3,4]

pairRemoval(String, String, String)

This is a public static function that takes three Strings as arguments and returns a String.

You will be given three strings, the first string is a sentence known as text that contains at least one occurrence of left pattern and right pattern. The second and third arguments of the function are the left and right patterns respectively. Left pattern and right pattern are single characters strings that you are attempting to remove from the string. Your goal is to remove only the patterns when the left pattern has an equal number of corresponding right patterns. The patterns are removed in pairs only when there is a balanced number of left and right patterns. The patterns may be nested within the text and there is no guarantee that a left pattern will occur before the right pattern.

Arguments:

String text - The string with the substring to be removed

String leftPattern - A pattern that the substring must start with

String rightPattern - A pattern that the substring must end with

returns String - The given text with the paired patterns removed

Example:

Example 1:

text = { { Muscat } } { } mecum tollgate } poultry quarrymen pantheon asteria

leftPattern = {

rightPattern = }

return = Muscat mecum tollgate } poultry quarrymen pantheon asteria

Example 2:

text = merioneth ( smickly helotage yarr ) ethmoidal ) ) ) digitinervate

leftPattern = (

rightPattern = )

return =. merioneth smickly helotage yarr ethmoidal ) ) ) digitinervate

Example 3:

text = southland palladic } { pasillo { } seeableness } { { normanesque

leftPattern = {

rightPattern = }

return = southland palladic pasillo seeableness { normanesque

multiplyMatrices(int[][], int[][])

This is a public static function that takes two 2D array's (int[][]) also known as matrices and returns the dot product of the two matrices. In other words this function is suppose to multiply the matrices it receives and return the product. For more information on how to multipy a matrices please recieve this tutorial. You can expect the number of columns in the first matrix to be the same number of rows in the second matrix.

Arguments:

int[][] matrixA - An n x m matrix

int[][] matrix - An p x n matrix

returns int[][] - The product matrix.

Examples:

Matrix A: [[55,30,12],[66,86,29],[89,90,38]] Matrix B: [[23,84],[11,63],[11,21]] Output: [[1727,6762],[2783,11571],[3455,13944]] Matrix A: [[93,68,4],[48,44,95],[18,99,19]] Matrix B: [[56,81,6],[91,64,44],[21,6,63]] Output: [[11480,11909,3802],[8687,7274,8209],[10416,7908,5661]] Matrix A: [[36],[77],[80]] Matrix B: [[25,28,37]] Output: [[900,1008,1332],[1925,2156,2849],[2000,2240,2960]] Matrix A: [[86]] Matrix B: [[67,10,5]] Output: [[5762,860,430]]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!