Question: Create a function which combines the elements of two arrays into one ( omitting all repeating values ). You will also need to create /
Create a function which combines the elements of two arrays into one (omitting all repeating values). You will also need to create / use a helper function which will determine if an array has a certain value in it or not. Both of these functions are to be written within one source file.
//Code needs to be in basic java language
See next page of more details on requirements and tips.
Function 1 isNumberInArray: Given two arguments, first an integer and second an integer array, this function will determine whether or not the array parameter contains an element with the same value as the integer parameter. If so, it'll return true, otherwise, it'll return false.
Function 2 unionArrays: Given two integer array arguments, this function will return an integer array which contains the union of both arrays elements (as seen in sample on last page).
Your union array must NOT contain ANY duplicate elements
For example, a union of {1, 2, 2} and {2, 3} should NOT result in this: {1, 2, 2, 2, 3}
You MUST utilize the "isNumberInArray" function in this function's body / implementation
Your union array DOESN'T need to be sorted
Your union array doesn't need to be of perfect length, you can set the size of the union array to just be the sum of the parameter arrays' sizes. This also means you don't need to worry about the "trailing zeros" your union array result may have
For example, a union of {1, 2, 3} and {2, 3, 4} resulting in {1, 2, 3, 4, 0, 0} is okay
Your union array CANNOT have any "gaps" in it, so for example, a union of {1, 2, 3} and {3, 4, 5} shouldn't look like this {1, 2, 3, 0, 4, 5}, nor this {1, 2, 0, 3, 4, 5}
Requirements:
As per usual, be sure to leave some comments (in your code) on how certain complex / unique parts of your program work.
Be sure to follow the instructions outlined for each function [below] EXACTLY as described. This includes small things such as making sure your functions are defined with the right names (and are spelled correctly), using the appropriate / necessary data type for your parameter(s) / return type, etc.
Both functions MUST exist in the same source file. DO NOT create separate files for each function.
Your final solution should NOT have any print statements anywhere in the file. You can of course utilize print statements to test your code / numbers as your developing this program, just be sure to delete them once your done.
DO NOT use the '...' operator anywhere in your functions' parameter list.
Your main method does NOT need to have any code in it. Ideally, you would use it for testing purposes to see if the return results of different function calls (with varying arguments) works out as expected
What's important for this assignment is that all the function definitions you create are formatted correctly and work as expected.
I also recommend you create a "printArray" function to help you examine your arrays when testing / debugging your code
This assignment doesn't require the use of multi-dimensional arrays (nor should it)
Finish the "isNumberInArray" function first, as that is really easy to implement.
As for the "unionArrays" function:Use for-each loops
I also recommend you establish a variable beforehand to keep track of the union array's index as more elements are assigned into it. Think back to how loops and variables work and how you can use them to your advantage here.
As stated in the guidelines above, your union array doesn't need to be of perfect length, so when you're defining it, have the size declaration (of your union array) just be based of the sum of the two array parameters' lengths
IE. int unionArray[] = new int [ + ];
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
