Question: (8pts)Task 1: Add three methods: union, intersection, and differenceto the interface BagInterface for the ADT bag.The detailed descriptionof the three methodsand how to call the
(8pts)Task 1: Add three methods: union, intersection, and differenceto the interface BagInterface for the ADT bag.The detailed descriptionof the three methodsand how to call the three methodscouldbe found on pages 2 and 3 of this assignment.Note: thethree methods to implement arefor Bags, not for Sets.
(36pts)Task2:Implementthe three methods,union, intersection, and difference,for the class ResizeableArrayBag. Note: the class ResizeableArrayBag presents an implementation of the ADT bag using a resizable array.
(36pts)Task 3:Implementthe three methods,union, intersection, and difference,for the class LinkedBag. Note: the class LinkedBag presents an implementation of the ADT bag using a linked chain.
(10pts)Task 4:Writea client program, ArrayBagTest.java, which contains a main method to test the three methods(union, intersection, and difference)youimplemented for the class ResizeableArrayBag.Note that when you examine the method difference, please test bothbag2.difference(bag1)andbag1.difference(bag2), given two bagsbag2 andbag1.
(10pts)Task 5:Writea client program, LinkedBagTest.java, which contains a main method to test the three methods(union, intersection, and difference) youimplemented for the class LinkedBag.Note that when you examine the method difference, please test bothbag2.difference(bag1)andbag1.difference(bag2), given two bagsbag2 andbag1.
*Union
The union of two collections consists of their contents combined into a new collection. Add a method union to theinterface BagInterface for the ADT bag that returns as a new bag the union of the bag receiving the call to themethod and the bag that is the methods one argument. Include sufficient comments to fully specify the method.Note that the union of two bags might contain duplicate items. For example, if object x occurs five times in onebag and twice in another, the union of these bags contains x seven times. Specifically, suppose that bag1 and bag2 areBag objects, where Bag implements BagInterface; bag1 contains the String objects a, b, and c; and bag2 containsthe String objects b, b, d, and e.After the statementBagInterface
*Intersection
The intersection of two collections is a new collection of the entries that occur in both collections. That is, it containsthe overlapping entries. Add a method intersection to the interface BagInterface for the ADT bag thatreturns as a new bag the intersection of the bag receiving the call to the method and the bag that is the methodsone argument. Include sufficient comments to fully specify the method.Note that the intersection of two bags might contain duplicate items. For example, if object x occurs fivetimes in one bag and twice in another, the intersection of these bags contains x twice. Specifically, suppose thatbag1 and bag2 are Bag objects, where Bag implements BagInterface;bag1 contains the String objects a, b, andc; and bag2 contains the String objects b, b, d, and e.After the statementBagInterface
*Difference
The difference of two collections is a new collection of the entries that would be left in one collection after removingthose that also occur in the second. Add a method difference to the interface BagInterface for the ADT bagthat returns as a new bag the difference of the bag receiving the call to the method and the bag that is the methodsone argument. Include sufficient comments to fully specify the method.Note that the difference of two bags might contain duplicate items. For example, if object x occurs five timesin one bag and twice in another, the difference of these bags contains x three times. Specifically, suppose that bag1and bag2 are Bag objects, where Bag implementsBagInterface; bag1 contains the String objects a, b, and c; andbag2 contains the String objects b, b, d, and e. After the statementBagInterface leftOver1 = bag1.difference(bag2);executes, the bag leftOver1 contains the strings a and c. After the statementBagInterface leftOver2 = bag2.difference(bag1);executes, the bag leftOver2 contains the strings b, d, and e. Note that difference does not affect the contents ofbag1 and bag
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
