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,

  1. Write a class called RandomIntegerArrayCreator that:
  1. upon its object instantiation:
    1. 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},
    2. 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,
  2. has two accessor methods:
    1. public int getArraySize() that will return the array size,
    2. public int[] getArray() that will return the reference to the random integer array that was generated.

  1. Write a class called CommonElements with a single method main that will:

  1. Create and obtain two integer arrays (arrayA and arrayB) using RandomIntegerArrayCreator type objects and its methods,
  2. 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),
  3. display the result using the format shown below (see Sample Output box).
  4. Constraints / notes:

  5. 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,
  6. Arrays A and B do NOT have to be of the same size,
  7. Arrays A and B CAN be empty (no elements),
  8. Arrays A and B will NOT be sorted.
  9. 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

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!