I am trying to do a Distributive Law in my code but somehow, the output always returns false.
Here is an example of my Set class with Union, Intersection and Equality method in it:
class Set { // Instance variable. private ArrayList<Zodiac> s; // Default constructor. public Set() { this.s = new ArrayList<Zodiac>(); } // Copy constructor. public Set(Set otherSet) { this.s = new ArrayList<Zodiac>(otherSet.s); for (Zodiac z : otherSet.s) { s.add(z); } } } here is my distributiveExample method:
private static void distributiveExample() { Set setA1 = new Set(getASet()); Set setB1 = new Set(getASet()); Set setC1 = new Set(getASet()); Set setA2 = new Set(setA1); Set setB2 = new Set(setB1); Set setC2 = new Set(setC1); System.out.printf("We wish to prove: A U (B I C) = (A U B) I (A U C).\n"); System.out.printf("\n"); System.out.printf("Given sets\n"); System.out.printf("\t A = {%s}%n", setA1); System.out.printf("\t B = {%s}%n", setB1); System.out.printf("\t C = {%s}%n", setC1); System.out.printf("\n"); System.out.printf("\t A = {%s}%n", setA2); System.out.printf("\t B = {%s}%n", setB2); System.out.printf("\t C = {%s}%n", setC2); System.out.printf("\n"); setB1.intersection(setC1); setA1.union(setB1); System.out.printf("LHS analysis\n"); System.out.printf("\t LHS = {%s}%n", setA1); setA2.union(setB2); setA2.union(setC2); setA2.intersection(setA2); System.out.printf("RHS analysis\n"); System.out.printf("\t RHS = {%s}%n", setA2); System.out.printf("\n"); System.out.printf("Conclusion\n"); System.out.printf("\t LHS = RHS is %b%n", setA1.equality(setA2)); System.out.printf("-----------------------------------------\n"); System.out.printf("\n"); } if LHS = RHS:

in the output, the LHS = RHS is true but somehow its return false. Therefore, I am unsure what I am doing wrong here.
Thank you.
Sets? What type are their elements? If they are instances ofjava.util.Set, don't use raw types, but insteadSet<String>(or whatever).