Question: JAVA please 1. Write the contains method and test it for a bag containing strings. 2. Define the method intersection for the ArrayBag class. Include
JAVA please
1. Write the contains method and test it for a bag containing strings.
2. Define the method intersection for the ArrayBag class. Include the following line in the BagInterface: public BagInterface intersection(BagInterface anotherBag);
Use the union method (shown below). Your main code must create two bags having strings and show the result of the intersection.
A union might contain duplicates.
The method should not alter either bag. The current bag and the bag sent in as a parameter should be the same when the method ends.
The method header is:
public BagInterface
Example:
bag1 contains (1, 2, 3)
bag2 contains (2, 2, 4, 5)
bag1.union(bag2) will return a new bag that contains (1, 2, 3, 2, 2, 4, 5).
The contents of bag1 and bag2 would be the same.
(The order of the union bag might not match the above, since bags are unordered.)

Write the contains method and test it
public BagInterface
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
