Tpe Word
Tpe Word
I. Project presenttion
II. Implementation
a. isEmpty
b. cardinal
c. ajouter
d. retirer
e. union
f. intersection
III. Test and validation
IV. Conclusion
II. Implementation
//here we import the Set interface from java util
import java.util.Set;
import java.util.HashSet;
this.ensemble = ensemble;
pg. 1
Made by Tsem Idriss Terrance
}
return this.ensemble.isEmpty();
return this.ensemble.size();
this.ensemble.add(e);
this.ensemble.remove(e);
// e. intersection method takes two sets of type T (generic type)the returns a set of all
elements found in the sets
pg. 2
Made by Tsem Idriss Terrance
// f. intersection method takes two sets of type T (generic type)the returns a set of all elements
found in both sets
// g. this method takes a set then calculates its compliment using the set we used to initialize the
class as universal set
complementResult.removeAll(complementSet);
pg. 3
Made by Tsem Idriss Terrance
III. Test And Validation
import java.util.Set;
import java.util.HashSet;
universalSet.add(1);
universalSet.add(2);
universalSet.add(3);
universalSet.add(4);
universalSet.add(5);
set1.add(2);
set1.add(3);
set1.add(4);
set2.add(4);
set2.add(5);
set2.add(6);
pg. 4
Made by Tsem Idriss Terrance
System.out.println("Is the universal set empty? " + ensemble.estVide()); // false
pg. 5
Made by Tsem Idriss Terrance
IV. Conclusion
In conclusion, this project successfully demonstrates the implementation of a generic Ensemble
class in Java, which supports essential set operations such as checking if a set is empty, calculating
its cardinality, adding or removing elements, and performing union, intersection, and complement
operations. By leveraging Java's Set interface and HashSet implementation, the project provides a
flexible and reusable structure for manipulating sets of any type. The use of generics ensures type
safety, while the inclusion of fundamental set operations makes it a powerful tool for various
applications that require set theory-based calculations.
pg. 6
Made by Tsem Idriss Terrance