In: Computer Science
1. What is the ouput (what are in the Bag) when the 2 below lines are executed? Please show the steps. String[] items = {"Z", "Y", "Y", "X", "S", "C", "A", "E", "M"}; testAdd(aBag, items);
2.
What is the output (what are in the Bag) when the 3 below lines are executed? Please show the steps.
String[] testString = { "X", "Y", "Z" };
aBag.removeAllOccurences(testString);
displayBag(aBag);
In this answer, I am assuming the bag is empty initially.
aBag = { }
(1)
String[] items = {"Z", "Y", "Y", "X", "S", "C", "A", "E", "M"};
testAdd(aBag, items);
When the above two lines are executed, then all the strings in the items array will be added to the bag.
Output: aBag = {"Z", "Y", "Y", "X", "S", "C", "A", "E", "M"}
(2)
String[] testString = { "X", "Y", "Z" };
aBag.removeAllOccurences(testString);
displayBag(aBag);
When the above three lines are executed, then all the strings in the testString array will be removed from the bag.
If there are multiple occurrences of any string, all occurrences will be removed.
There is one occurrence of ''X", two occurrences of "Y", one occurrence of "Z" in abag, those strings will be removed from the bag, and the output bag contents will be:
Output: aBag = {"S", "C", "A", "E", "M"}
----------------------------------------
I hope this helps you,
Please rate this answer if it helped you,
Please comment on this answer, for any further
discussion
Thanks for the opportunity