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 everything = bag1.union(bag2);3executes, the bag everything contains the strings a, b, b, b, c, d, and e. Note that union does not affect the contentsof bag1 and bag2, and the order of data items in the resulting bag everything doesnt matter.

*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 commonItems = bag1.intersection(bag2);executes, the bag commonItems contains only the string b. If b had occurred in bag1 twice, commonItems wouldhave contained two occurrences of b, since bag2 also contains two occurrences of b. Note that intersection doesnot affect the contents of bag1 and bag2.

*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

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!