SlideShare a Scribd company logo
1 of 5
Download to read offline
I really need help with the code for this in Java.
Set operations using iterators: implement a program that creates the sets below (as ArrayLists of
Integers), and then finds the result of the operations below. You only need a single .java file with
the main routine; you do not have to put each set operation in its own method. Do NOT use the
toArray( ) method; you will only need the add( ), addAll( ), contains( ), iterator( ), isEmpty( ),
and remove( ) methods defined for the ArrayList. Recall that setscannot have duplicate entries; it
is up to you to enforce this! (Note: in Java a Set is an interface, but it can also be a class, as all
interfaces are also classes!) Sets:
U = {1,2,3,4,5,6,7,8,9,10} (universe set)
E = {2,4,6,8,10}
O = {1,3,5,7,9}
A = {3,4,5}
B = {5,6,7}
C = { } (empty set)
Operations: find
A union B
A intersect B
A complement
O minus B
E minus A
A symmetric difference B (the symmetric difference of 2 sets is the elements in either, but not in
their intersection)
Subsets: write a method that takes two sets, determines if the first is a subset of the second, and
returns true or false. Then answer these questions (by writing code): is C a subset of U; is E and
subset of U; and, is A a subset of B?
Solution
//code has been tested on eclipse
import java.util.ArrayList;
public class HelloWorld{
public static boolean isSubset(ArrayList A, ArrayList B) { //method to //check subset
return B.containsAll(A);
}
public static void main(String []args){ //main method
ArrayList U=new ArrayList(); //Arraylist for storing elements of union
U.add(1); U.add(2);U.add(3); U.add(4); U.add(5); U.add(6); U.add(7); U.add(8); U.add(9);
U.add(10);//entering //elements of union set
ArrayList E=new ArrayList(); //Arraylist for storing elements of set E
E.add(2); E.add(4); E.add(6); E.add(8); E.add(10); //entering elements of set E
ArrayList O=new ArrayList(); //Arraylist for storing elements of set O
O.add(1);O.add(3);O.add(5);O.add(7);O.add(9); //entering elements of set O
ArrayList A=new ArrayList(); //Arraylist for storing elements of set A
A.add(3); A.add(4); A.add(5); //entering elements of set A
ArrayList B=new ArrayList(); //Arraylist for storing elements of set B
B.add(5);B.add(6);B.add(7); //entering elements of set B
ArrayList C=new ArrayList(); //Arraylist for storing elements of set C
ArrayList UnionA_B=new ArrayList(); //Arraylist for storing elements of Union of A and B
UnionA_B.addAll(A); //Union operation using Addall
for(Integer x:B) //loop to find union of A and B
{
if(!(A.contains(x)))
UnionA_B.add(x); //add elements of union of A and B
}
System.out.println("Union of set A and B "); //printing elements of union A and B
for(Integer x:UnionA_B)
System.out.println(x+" ");
ArrayList IntsctA_B=new ArrayList(); //Arraylist for storing elements of //Intersection of A and
B
for(Integer x:A){ //loop to find Intersection of A and B
if(B.contains(x))
IntsctA_B.add(x); //add elements of Intersection of A and B
}
System.out.println("Intersection of set A and B "); //printing elements of Intersection A and B
for(Integer x:IntsctA_B)
System.out.println(x+" ");
ArrayList Acomplmnt=new ArrayList(); //Arraylist for storing elements of Complement //of A
for(Integer x:U){ //loop to find Complement of A
if(!(A.contains(x)))
Acomplmnt.add(x); //add elements of Complement of A
}
System.out.println("Complement of set A "); //printing elements of Complement A
for(Integer x:Acomplmnt)
System.out.println(x+" ");
ArrayList OminusB=new ArrayList(); //Arraylist for storing elements of O minus B
OminusB.addAll(O);
for(Integer x:O){ //loop to find O minus B
if(B.contains(x))
OminusB.remove(x); //remove elements of b from O,i.e OminusB
}
System.out.println("O minus B "); //printing elements of O minus B
for(Integer x: OminusB)
System.out.println(x+" ");
ArrayList EminusA=new ArrayList(); //Similarly for operation E minus A
EminusA.addAll(E);
for(Integer x:E){
if(A.contains(x))
EminusA.remove(x);
}
System.out.println("E minus A ");
for(Integer x: EminusA)
System.out.println(x+" ");
ArrayList AsymdfrB=new ArrayList(); //ArrayList for storing symmetric //difference of A and
B
UnionA_B.removeAll(IntsctA_B);
System.out.println("A symmetric difference B");
for(Integer x: UnionA_B) //printing elements of symmetric difference of A and B
System.out.println(x+" ");
System.out.println("Is C a subset of U : " + isSubset(C,U)); //is C a subset of U
System.out.println("Is E a subset of U : " + isSubset(E,U)); //is E a subset of U
System.out.println("Is A a subset of B : " + isSubset(A,B)); //is A a subset of B
}
}
***********OUTPUT*********
Union of set A and B
3
4
5
6
7
Intersection of set A and B
5
Complement of set A
1
2
6
7
8
9
10
O minus B
1
3
9
E minus A
2
6
8
10
A symmetric difference B
3
4
6
7
Is C a subset of U : true
Is E a subset of U : true
Is A a subset of B : false
***********OUTPUT*********
Note:I have used arraylist and functions like add,addAll,contains,remove and had not make
different methods for each operations,please let me know in case of any doubt,Thanks.

More Related Content

Similar to I really need help with the code for this in Java.Set operations u.pdf

Please add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docxPlease add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docxStewartt0kJohnstonh
 
ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
 ReverseList.javaimport java.util.ArrayList;public class Rever.pdf ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
ReverseList.javaimport java.util.ArrayList;public class Rever.pdfaryan9007
 
Implement the additional 5 methods as indicated in the LinkedList fi.pdf
Implement the additional 5 methods as indicated in the LinkedList fi.pdfImplement the additional 5 methods as indicated in the LinkedList fi.pdf
Implement the additional 5 methods as indicated in the LinkedList fi.pdffootstatus
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdffreddysarabia1
 
Write a java class LIST that outputsmainpublic class Ass.pdf
Write a java class LIST that outputsmainpublic class Ass.pdfWrite a java class LIST that outputsmainpublic class Ass.pdf
Write a java class LIST that outputsmainpublic class Ass.pdfebrahimbadushata00
 
Linked list (java platform se 8 )
Linked list (java platform se 8 )Linked list (java platform se 8 )
Linked list (java platform se 8 )charan kumar
 
import java.util.ArrayList; import java.util.List; .pdf
import java.util.ArrayList; import java.util.List;   .pdfimport java.util.ArrayList; import java.util.List;   .pdf
import java.util.ArrayList; import java.util.List; .pdfanuradhasilks
 
Java ArrayList Tutorial | Edureka
Java ArrayList Tutorial | EdurekaJava ArrayList Tutorial | Edureka
Java ArrayList Tutorial | EdurekaEdureka!
 
01-intro_stacks.ppt
01-intro_stacks.ppt01-intro_stacks.ppt
01-intro_stacks.pptsoniya555961
 
Computer notes - Josephus Problem
Computer notes - Josephus ProblemComputer notes - Josephus Problem
Computer notes - Josephus Problemecomputernotes
 
I need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdfI need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdffantoosh1
 
computer notes - Data Structures - 5
computer notes - Data Structures - 5computer notes - Data Structures - 5
computer notes - Data Structures - 5ecomputernotes
 
Write a method countUnique that takes a List of integers as a parame.pdf
Write a method countUnique that takes a List of integers as a parame.pdfWrite a method countUnique that takes a List of integers as a parame.pdf
Write a method countUnique that takes a List of integers as a parame.pdfMALASADHNANI
 
collectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptxcollectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptxhemanth248901
 
Array list (java platform se 8 )
Array list (java platform se 8 )Array list (java platform se 8 )
Array list (java platform se 8 )charan kumar
 
Create a JAVA Program that traverses through an array recursively- rat.docx
Create a JAVA Program that traverses through an array recursively- rat.docxCreate a JAVA Program that traverses through an array recursively- rat.docx
Create a JAVA Program that traverses through an array recursively- rat.docxmrichard5
 

Similar to I really need help with the code for this in Java.Set operations u.pdf (20)

Please add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docxPlease add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docx
 
ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
 ReverseList.javaimport java.util.ArrayList;public class Rever.pdf ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
 
Implement the additional 5 methods as indicated in the LinkedList fi.pdf
Implement the additional 5 methods as indicated in the LinkedList fi.pdfImplement the additional 5 methods as indicated in the LinkedList fi.pdf
Implement the additional 5 methods as indicated in the LinkedList fi.pdf
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
 
Write a java class LIST that outputsmainpublic class Ass.pdf
Write a java class LIST that outputsmainpublic class Ass.pdfWrite a java class LIST that outputsmainpublic class Ass.pdf
Write a java class LIST that outputsmainpublic class Ass.pdf
 
Linked list (java platform se 8 )
Linked list (java platform se 8 )Linked list (java platform se 8 )
Linked list (java platform se 8 )
 
import java.util.ArrayList; import java.util.List; .pdf
import java.util.ArrayList; import java.util.List;   .pdfimport java.util.ArrayList; import java.util.List;   .pdf
import java.util.ArrayList; import java.util.List; .pdf
 
Java ArrayList Tutorial | Edureka
Java ArrayList Tutorial | EdurekaJava ArrayList Tutorial | Edureka
Java ArrayList Tutorial | Edureka
 
WDD_lec_06.ppt
WDD_lec_06.pptWDD_lec_06.ppt
WDD_lec_06.ppt
 
01-intro_stacks.ppt
01-intro_stacks.ppt01-intro_stacks.ppt
01-intro_stacks.ppt
 
Advanced core java
Advanced core javaAdvanced core java
Advanced core java
 
Computer notes - Josephus Problem
Computer notes - Josephus ProblemComputer notes - Josephus Problem
Computer notes - Josephus Problem
 
ArrayList.docx
ArrayList.docxArrayList.docx
ArrayList.docx
 
I need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdfI need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdf
 
computer notes - Data Structures - 5
computer notes - Data Structures - 5computer notes - Data Structures - 5
computer notes - Data Structures - 5
 
Write a method countUnique that takes a List of integers as a parame.pdf
Write a method countUnique that takes a List of integers as a parame.pdfWrite a method countUnique that takes a List of integers as a parame.pdf
Write a method countUnique that takes a List of integers as a parame.pdf
 
collectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptxcollectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptx
 
Array list (java platform se 8 )
Array list (java platform se 8 )Array list (java platform se 8 )
Array list (java platform se 8 )
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
 
Create a JAVA Program that traverses through an array recursively- rat.docx
Create a JAVA Program that traverses through an array recursively- rat.docxCreate a JAVA Program that traverses through an array recursively- rat.docx
Create a JAVA Program that traverses through an array recursively- rat.docx
 

More from dbrienmhompsonkath75

Give examples of system which can achieve some security requirement.pdf
Give examples of system which can achieve some security requirement.pdfGive examples of system which can achieve some security requirement.pdf
Give examples of system which can achieve some security requirement.pdfdbrienmhompsonkath75
 
Help me with these questions please.1. Name four characteristics t.pdf
Help me with these questions please.1. Name four characteristics t.pdfHelp me with these questions please.1. Name four characteristics t.pdf
Help me with these questions please.1. Name four characteristics t.pdfdbrienmhompsonkath75
 
Describe current and emerging roles of the patient record in HIT toda.pdf
Describe current and emerging roles of the patient record in HIT toda.pdfDescribe current and emerging roles of the patient record in HIT toda.pdf
Describe current and emerging roles of the patient record in HIT toda.pdfdbrienmhompsonkath75
 
Dont change the templates, and just fill out the TODO parts on .pdf
Dont change the templates, and just fill out the  TODO parts on .pdfDont change the templates, and just fill out the  TODO parts on .pdf
Dont change the templates, and just fill out the TODO parts on .pdfdbrienmhompsonkath75
 
Directions Problem 1. A female with Muppetrus bristle mates with a .pdf
Directions Problem 1. A female with Muppetrus bristle mates with a .pdfDirections Problem 1. A female with Muppetrus bristle mates with a .pdf
Directions Problem 1. A female with Muppetrus bristle mates with a .pdfdbrienmhompsonkath75
 
Describe the roll of each of the following in membrane transport a.pdf
Describe the roll of each of the following in membrane transport a.pdfDescribe the roll of each of the following in membrane transport a.pdf
Describe the roll of each of the following in membrane transport a.pdfdbrienmhompsonkath75
 
Compare and contrast transactional and transformational leadership.pdf
Compare and contrast transactional and transformational leadership.pdfCompare and contrast transactional and transformational leadership.pdf
Compare and contrast transactional and transformational leadership.pdfdbrienmhompsonkath75
 
Calculator Which of the following is not an asset Oa, owners equi.pdf
Calculator Which of the following is not an asset Oa, owners equi.pdfCalculator Which of the following is not an asset Oa, owners equi.pdf
Calculator Which of the following is not an asset Oa, owners equi.pdfdbrienmhompsonkath75
 
You are installing a KVM switch for a small business customer so tha.pdf
You are installing a KVM switch for a small business customer so tha.pdfYou are installing a KVM switch for a small business customer so tha.pdf
You are installing a KVM switch for a small business customer so tha.pdfdbrienmhompsonkath75
 
Why is metabolism important for physiological processesSolution.pdf
Why is metabolism important for physiological processesSolution.pdfWhy is metabolism important for physiological processesSolution.pdf
Why is metabolism important for physiological processesSolution.pdfdbrienmhompsonkath75
 
Which macromolecule is primarily responsible for producing the pheno.pdf
Which macromolecule is primarily responsible for producing the pheno.pdfWhich macromolecule is primarily responsible for producing the pheno.pdf
Which macromolecule is primarily responsible for producing the pheno.pdfdbrienmhompsonkath75
 
which invertebrate phylum is considered the most evolutionarily succe.pdf
which invertebrate phylum is considered the most evolutionarily succe.pdfwhich invertebrate phylum is considered the most evolutionarily succe.pdf
which invertebrate phylum is considered the most evolutionarily succe.pdfdbrienmhompsonkath75
 
What suggestions would you offer to parents and teachers who want to.pdf
What suggestions would you offer to parents and teachers who want to.pdfWhat suggestions would you offer to parents and teachers who want to.pdf
What suggestions would you offer to parents and teachers who want to.pdfdbrienmhompsonkath75
 
What is the F2 generation when the F1 generation of +++y cv f is cr.pdf
What is the F2 generation when the F1 generation of +++y cv f is cr.pdfWhat is the F2 generation when the F1 generation of +++y cv f is cr.pdf
What is the F2 generation when the F1 generation of +++y cv f is cr.pdfdbrienmhompsonkath75
 
What features on the plasmid allows it to replicate independent o.pdf
What features on the plasmid allows it to replicate independent o.pdfWhat features on the plasmid allows it to replicate independent o.pdf
What features on the plasmid allows it to replicate independent o.pdfdbrienmhompsonkath75
 
What are the use of Fibonacci numbers or the Golden Ratio in nature,.pdf
What are the use of Fibonacci numbers or the Golden Ratio in nature,.pdfWhat are the use of Fibonacci numbers or the Golden Ratio in nature,.pdf
What are the use of Fibonacci numbers or the Golden Ratio in nature,.pdfdbrienmhompsonkath75
 
Based on the following schematic with 3 D flip-flops, Write complete .pdf
Based on the following schematic with 3 D flip-flops, Write complete .pdfBased on the following schematic with 3 D flip-flops, Write complete .pdf
Based on the following schematic with 3 D flip-flops, Write complete .pdfdbrienmhompsonkath75
 
Although O_2 does not participate directly in the reactions of the TC.pdf
Although O_2 does not participate directly in the reactions of the TC.pdfAlthough O_2 does not participate directly in the reactions of the TC.pdf
Although O_2 does not participate directly in the reactions of the TC.pdfdbrienmhompsonkath75
 
8. Which of the following is NOT a transcriptionally repressed genom.pdf
8. Which of the following is NOT a transcriptionally repressed genom.pdf8. Which of the following is NOT a transcriptionally repressed genom.pdf
8. Which of the following is NOT a transcriptionally repressed genom.pdfdbrienmhompsonkath75
 
49. Autonomic nervous system function is influenced by A) cerebral co.pdf
49. Autonomic nervous system function is influenced by A) cerebral co.pdf49. Autonomic nervous system function is influenced by A) cerebral co.pdf
49. Autonomic nervous system function is influenced by A) cerebral co.pdfdbrienmhompsonkath75
 

More from dbrienmhompsonkath75 (20)

Give examples of system which can achieve some security requirement.pdf
Give examples of system which can achieve some security requirement.pdfGive examples of system which can achieve some security requirement.pdf
Give examples of system which can achieve some security requirement.pdf
 
Help me with these questions please.1. Name four characteristics t.pdf
Help me with these questions please.1. Name four characteristics t.pdfHelp me with these questions please.1. Name four characteristics t.pdf
Help me with these questions please.1. Name four characteristics t.pdf
 
Describe current and emerging roles of the patient record in HIT toda.pdf
Describe current and emerging roles of the patient record in HIT toda.pdfDescribe current and emerging roles of the patient record in HIT toda.pdf
Describe current and emerging roles of the patient record in HIT toda.pdf
 
Dont change the templates, and just fill out the TODO parts on .pdf
Dont change the templates, and just fill out the  TODO parts on .pdfDont change the templates, and just fill out the  TODO parts on .pdf
Dont change the templates, and just fill out the TODO parts on .pdf
 
Directions Problem 1. A female with Muppetrus bristle mates with a .pdf
Directions Problem 1. A female with Muppetrus bristle mates with a .pdfDirections Problem 1. A female with Muppetrus bristle mates with a .pdf
Directions Problem 1. A female with Muppetrus bristle mates with a .pdf
 
Describe the roll of each of the following in membrane transport a.pdf
Describe the roll of each of the following in membrane transport a.pdfDescribe the roll of each of the following in membrane transport a.pdf
Describe the roll of each of the following in membrane transport a.pdf
 
Compare and contrast transactional and transformational leadership.pdf
Compare and contrast transactional and transformational leadership.pdfCompare and contrast transactional and transformational leadership.pdf
Compare and contrast transactional and transformational leadership.pdf
 
Calculator Which of the following is not an asset Oa, owners equi.pdf
Calculator Which of the following is not an asset Oa, owners equi.pdfCalculator Which of the following is not an asset Oa, owners equi.pdf
Calculator Which of the following is not an asset Oa, owners equi.pdf
 
You are installing a KVM switch for a small business customer so tha.pdf
You are installing a KVM switch for a small business customer so tha.pdfYou are installing a KVM switch for a small business customer so tha.pdf
You are installing a KVM switch for a small business customer so tha.pdf
 
Why is metabolism important for physiological processesSolution.pdf
Why is metabolism important for physiological processesSolution.pdfWhy is metabolism important for physiological processesSolution.pdf
Why is metabolism important for physiological processesSolution.pdf
 
Which macromolecule is primarily responsible for producing the pheno.pdf
Which macromolecule is primarily responsible for producing the pheno.pdfWhich macromolecule is primarily responsible for producing the pheno.pdf
Which macromolecule is primarily responsible for producing the pheno.pdf
 
which invertebrate phylum is considered the most evolutionarily succe.pdf
which invertebrate phylum is considered the most evolutionarily succe.pdfwhich invertebrate phylum is considered the most evolutionarily succe.pdf
which invertebrate phylum is considered the most evolutionarily succe.pdf
 
What suggestions would you offer to parents and teachers who want to.pdf
What suggestions would you offer to parents and teachers who want to.pdfWhat suggestions would you offer to parents and teachers who want to.pdf
What suggestions would you offer to parents and teachers who want to.pdf
 
What is the F2 generation when the F1 generation of +++y cv f is cr.pdf
What is the F2 generation when the F1 generation of +++y cv f is cr.pdfWhat is the F2 generation when the F1 generation of +++y cv f is cr.pdf
What is the F2 generation when the F1 generation of +++y cv f is cr.pdf
 
What features on the plasmid allows it to replicate independent o.pdf
What features on the plasmid allows it to replicate independent o.pdfWhat features on the plasmid allows it to replicate independent o.pdf
What features on the plasmid allows it to replicate independent o.pdf
 
What are the use of Fibonacci numbers or the Golden Ratio in nature,.pdf
What are the use of Fibonacci numbers or the Golden Ratio in nature,.pdfWhat are the use of Fibonacci numbers or the Golden Ratio in nature,.pdf
What are the use of Fibonacci numbers or the Golden Ratio in nature,.pdf
 
Based on the following schematic with 3 D flip-flops, Write complete .pdf
Based on the following schematic with 3 D flip-flops, Write complete .pdfBased on the following schematic with 3 D flip-flops, Write complete .pdf
Based on the following schematic with 3 D flip-flops, Write complete .pdf
 
Although O_2 does not participate directly in the reactions of the TC.pdf
Although O_2 does not participate directly in the reactions of the TC.pdfAlthough O_2 does not participate directly in the reactions of the TC.pdf
Although O_2 does not participate directly in the reactions of the TC.pdf
 
8. Which of the following is NOT a transcriptionally repressed genom.pdf
8. Which of the following is NOT a transcriptionally repressed genom.pdf8. Which of the following is NOT a transcriptionally repressed genom.pdf
8. Which of the following is NOT a transcriptionally repressed genom.pdf
 
49. Autonomic nervous system function is influenced by A) cerebral co.pdf
49. Autonomic nervous system function is influenced by A) cerebral co.pdf49. Autonomic nervous system function is influenced by A) cerebral co.pdf
49. Autonomic nervous system function is influenced by A) cerebral co.pdf
 

Recently uploaded

Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 

Recently uploaded (20)

Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 

I really need help with the code for this in Java.Set operations u.pdf

  • 1. I really need help with the code for this in Java. Set operations using iterators: implement a program that creates the sets below (as ArrayLists of Integers), and then finds the result of the operations below. You only need a single .java file with the main routine; you do not have to put each set operation in its own method. Do NOT use the toArray( ) method; you will only need the add( ), addAll( ), contains( ), iterator( ), isEmpty( ), and remove( ) methods defined for the ArrayList. Recall that setscannot have duplicate entries; it is up to you to enforce this! (Note: in Java a Set is an interface, but it can also be a class, as all interfaces are also classes!) Sets: U = {1,2,3,4,5,6,7,8,9,10} (universe set) E = {2,4,6,8,10} O = {1,3,5,7,9} A = {3,4,5} B = {5,6,7} C = { } (empty set) Operations: find A union B A intersect B A complement O minus B E minus A A symmetric difference B (the symmetric difference of 2 sets is the elements in either, but not in their intersection) Subsets: write a method that takes two sets, determines if the first is a subset of the second, and returns true or false. Then answer these questions (by writing code): is C a subset of U; is E and subset of U; and, is A a subset of B? Solution //code has been tested on eclipse import java.util.ArrayList; public class HelloWorld{ public static boolean isSubset(ArrayList A, ArrayList B) { //method to //check subset return B.containsAll(A); }
  • 2. public static void main(String []args){ //main method ArrayList U=new ArrayList(); //Arraylist for storing elements of union U.add(1); U.add(2);U.add(3); U.add(4); U.add(5); U.add(6); U.add(7); U.add(8); U.add(9); U.add(10);//entering //elements of union set ArrayList E=new ArrayList(); //Arraylist for storing elements of set E E.add(2); E.add(4); E.add(6); E.add(8); E.add(10); //entering elements of set E ArrayList O=new ArrayList(); //Arraylist for storing elements of set O O.add(1);O.add(3);O.add(5);O.add(7);O.add(9); //entering elements of set O ArrayList A=new ArrayList(); //Arraylist for storing elements of set A A.add(3); A.add(4); A.add(5); //entering elements of set A ArrayList B=new ArrayList(); //Arraylist for storing elements of set B B.add(5);B.add(6);B.add(7); //entering elements of set B ArrayList C=new ArrayList(); //Arraylist for storing elements of set C ArrayList UnionA_B=new ArrayList(); //Arraylist for storing elements of Union of A and B UnionA_B.addAll(A); //Union operation using Addall for(Integer x:B) //loop to find union of A and B { if(!(A.contains(x))) UnionA_B.add(x); //add elements of union of A and B } System.out.println("Union of set A and B "); //printing elements of union A and B for(Integer x:UnionA_B) System.out.println(x+" "); ArrayList IntsctA_B=new ArrayList(); //Arraylist for storing elements of //Intersection of A and B for(Integer x:A){ //loop to find Intersection of A and B if(B.contains(x)) IntsctA_B.add(x); //add elements of Intersection of A and B } System.out.println("Intersection of set A and B "); //printing elements of Intersection A and B for(Integer x:IntsctA_B) System.out.println(x+" ");
  • 3. ArrayList Acomplmnt=new ArrayList(); //Arraylist for storing elements of Complement //of A for(Integer x:U){ //loop to find Complement of A if(!(A.contains(x))) Acomplmnt.add(x); //add elements of Complement of A } System.out.println("Complement of set A "); //printing elements of Complement A for(Integer x:Acomplmnt) System.out.println(x+" "); ArrayList OminusB=new ArrayList(); //Arraylist for storing elements of O minus B OminusB.addAll(O); for(Integer x:O){ //loop to find O minus B if(B.contains(x)) OminusB.remove(x); //remove elements of b from O,i.e OminusB } System.out.println("O minus B "); //printing elements of O minus B for(Integer x: OminusB) System.out.println(x+" "); ArrayList EminusA=new ArrayList(); //Similarly for operation E minus A EminusA.addAll(E); for(Integer x:E){ if(A.contains(x)) EminusA.remove(x); } System.out.println("E minus A "); for(Integer x: EminusA) System.out.println(x+" "); ArrayList AsymdfrB=new ArrayList(); //ArrayList for storing symmetric //difference of A and B UnionA_B.removeAll(IntsctA_B);
  • 4. System.out.println("A symmetric difference B"); for(Integer x: UnionA_B) //printing elements of symmetric difference of A and B System.out.println(x+" "); System.out.println("Is C a subset of U : " + isSubset(C,U)); //is C a subset of U System.out.println("Is E a subset of U : " + isSubset(E,U)); //is E a subset of U System.out.println("Is A a subset of B : " + isSubset(A,B)); //is A a subset of B } } ***********OUTPUT********* Union of set A and B 3 4 5 6 7 Intersection of set A and B 5 Complement of set A 1 2 6 7 8 9 10 O minus B 1 3 9 E minus A
  • 5. 2 6 8 10 A symmetric difference B 3 4 6 7 Is C a subset of U : true Is E a subset of U : true Is A a subset of B : false ***********OUTPUT********* Note:I have used arraylist and functions like add,addAll,contains,remove and had not make different methods for each operations,please let me know in case of any doubt,Thanks.