The symbol is a set operation (like and ). For any two subsets A, B of a universal set , the set AB is defined as AB:=AB ={AllxAsuchthatx/B} As special cases, A is the same set as A, and AA is the same set as . (a) Draw a Venn Diagram for the sets A and B (assuming they partly overlap each other), and indicate the three regions corresponding to the three sets A B, A B and B A. (b) Is A B always a subset of A? State the reason. (c) By using De Morgan's Law, what is the complement of A B? Express the result by using A, B and the three basic set operations , and . (d) If is the sample space of a random experiment, and A and B are events, we would interpret A B as the event that A and B both occur. Interpret the event A B in a similar way, and prove that P(A B) = P(A) P(A B).
DEFINITION 7. Sets A and # are equal, denoted = D, when both sets have the same ele- ments. The way In which the elements are ordered does not matter. DEFINITION 8. A set A is a subset of set B, denoted A C B, If every element of set A is also an element of set D. DEFINITION 9. A set A Is a proper subset of set B, denoted A C B or A C B, if every element of set A is also an element of set # but both sets A and B are not equal. Some Useful Java ArrayList API Methods 1. ArrayList
listName = new ArrayList();: creates an empty array list, listName, that can store objects of the specified type. 2. listName.add(item);: appends the specified /tem to the (back of) the list. 3. listName.get(index);: returns the item In the array list with the specified index. Array lists use zero-based indexing. 4. listName.size();: returns the current length, number of items, in the specified array list. 5. listName.IsEmpty():: returns true if the length of listName is 0 and, false, otherwise. 6. listName.contains(item);: returns true if the array list contains the specified item and, false, otherwise. This project will have the following two classes: public class Set Complete the implementation of the Set class provided in the starter code by implementing the methods union, diff, equals, subset, and properSubset. public class SetDemo Complete the implementation of the SetDemo class provided in the starter code by implementing the generic methods setOperationsDemo and getMax. Implement the method setOperationsDemo so that it produces exactly the output shown below. In the output, u means union, n means intersection, and the minus sign means difference. The method getMax finds and returns the maximum element in the set.CSC 1351-03, Spring 2018, Lab 7 Name this project Set Create a project named Set that illustrates the use of generic classes and generic methods. Implementing a Generic Set Class DEFINITION 1. Generics is a way of defining classes, interfaces and methods by using type pa- rameters to represent types. A more technical term for generics is parametric polymorphism. A generic method, interface or class is fully specified at run time. In Java, a generic type can only be specialized using an object type. Every primitive type in Java has an associated object type (a wrapper class). DEFINITION 2. A set is a finite or Infinite collection of objects in which order has no significance, and multiplicity is generally also ignored. Members of a set are often referred to as elements and the notation a E A is used to denote that ar is an element of a set A. A set Is usually denoted as a list of elements. For example, {2, 3, 4,5, 6) is a set that contains five elements. In today's lab, you will Implement a generic class, the Set class. The class will be generic but its methods will not be generic. Some methods will use the formal type parameter of the class. In this lab, we introduce a basic software engineering concept called composition - one object is composed of another. A set is composed of a list. We will use the Java API ArrayList, also a generic class, to Implement the Set class. Basic Set Operations DEFINITION 3. The cardinality of a set is the number of elements that the set contains. For example, the cardinality of A = {2,3, 4, 5, 6}, denoted |A| Is 5. DEFINITION 4. The intersection of two sets A and B is the set of elements common to A and B. This is written An B , and is pronounced "intersection" or "cap." DEFINITION 5. The union of two sets A and B is the set obtained by combining the members of each without allowing multiplicity. This is written A U B, and is pronounced "union" or "cup ." DEFINITION 6. The difference of sets A and B, denoted A - B, is the set of elements belonging to set A but not B