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 to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
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
outputpackage 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
Last edited by robertm08; August 19th, 2013 at 01:05 AM. Reason: code tags
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.