Question: Write a class called RandomIntegerArrayCreator that: upon its object instantiation: will generate a random integer arraySize from the set {0, 1, 2, 3, 4, 5,
- Write a class called RandomIntegerArrayCreator that:
- upon its object instantiation:
- will generate a random integer arraySize from the set {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
- create a random integer array of size arraySize (15 OR LESS) with elements from the the set {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10} (integers can appear multiple times in this array,
- has two accessor methods:
- public int getArraySize() that will return the array size,
- public int[] getArray() that will return the reference to the random integer array that was generated.
- Write a class called CommonElements with a single method main that will:
- Create and obtain two integer arrays (arrayA and arrayB) using RandomIntegerArrayCreator type objects and its methods,
- find the number of common elements between arrayA and arrayB (say: if integer 2 appears in arrayA once and twice in arrayB, that counts as ONE common element between the two),
- display the result using the format shown below (see Sample Output box).
-
Constraints / notes:
- All array elements are integers from the the set {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10} and can appear multiple times in each array,
- Arrays A and B do NOT have to be of the same size,
- Arrays A and B CAN be empty (no elements),
- Arrays A and B will NOT be sorted.
-
Given these two sample arrays (orientation changed for readability):
Array A
Array B
2
3
1
0
1
5
4
3
4
0
5
2
1
2
2
5
Your program output should look like this:
Sample output
Array A: 2 3 1 0 1 5
Array B: 4 3 4 0 5 2 1 2 2 5
Element: # in A: # in B:
0 1 1
1 2 1
2 1 3
3 1 1
5 1 2
Number of common elements in A and B: 5
If there are no common elements (or one or two arrays are empty), just display:
Number of common elements in A and B: 0
Test your class with different arrays. Your solution does not need to be efficient, just effective.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
