I need help i have to write a program to verify if a set is a subset of the other that A intersect B intersect C = A' union B' union C'
I am new to this forum Thanks in advance
Printable View
I need help i have to write a program to verify if a set is a subset of the other that A intersect B intersect C = A' union B' union C'
I am new to this forum Thanks in advance
Welcome robertm08
What is it you need help with?
Sounds like the description is of several problems, choose one to work with first, and let us know what you get stuck on
outputCode Java:
package SetTheory; import java.util.HashSet; import java.util.Set; import java.util.TreeSet; public class test { /** * @param args */ public static Set intersection(Set setA, Set setB, Set setC) { Set S = new TreeSet(setA); S.retainAll(setB); S.retainAll(setC); return S; } public static Set union(Set setA, Set setB, Set setC) { Set M = new TreeSet(setA); M.addAll(setB); M.addAll(setC); return M; } public static Set notB (Set setA, Set setB, Set setC) { setA.removeAll(setB); setC.removeAll(setB); setA.addAll(setC); return setA; } public static Set notA (Set setA, Set setB, Set setC) { setB.removeAll(setA); setC.removeAll(setA); Set R = new TreeSet(setB); R.addAll(setC); return R; } public static void main(String[] args) { TreeSet set1 = new TreeSet(); TreeSet set2 = new TreeSet(); TreeSet set3 = new TreeSet(); set1.add('a'); set1.add('d'); set1.add('e'); set1.add('g'); set2.add('b'); set2.add('d'); set2.add('f'); set2.add('g'); set3.add('c'); set3.add('f'); set3.add('e'); set3.add('g'); System.out.println("Union:" + union(set1, set2, set3)); System.out.println("Intersection:" + intersection(set1, set2, set3)); System.out.println("B' = " + notB(set1, set2, set3)); System.out.println("A' = " + notA(set1, set2, set3)); } }
Union:[a, b, c, d, e, f, g]
Intersection:[g]
B' = [a, c, e]
A' = [b, d, f, g]
the first difference output from B' is correct because B' = (A-B)+(C-B) = a,c,e
i am confused because of the output of A' = (B-A)+(C-A) i need to make the output to be b,f,c
Please use code tags when posting code, assistance can be found on the Announcements Page.
Please do note that we do not provide solutions, we provide suggestions, but I do not understand what it is you need help with. What are you stuck on?
I am sorry Jps now i have fixed it sorry for my bad english
I'm sorry too... I still do not see your question or a description of the problem you are stuck on.