SlideShare a Scribd company logo
1 of 8
Download to read offline
Here is what I got so far, I don't know how to write union, intersection, and minus. Please
complete this code in Java.
do not use iterator
public class IntArraySet extends IntSet
{
private int[ ] data;
private int manyItems;
public IntArraySet( )
{
final int INITIAL_CAPACITY = 10;
manyItems = 0;
data = new int[INITIAL_CAPACITY];
}
public IntArraySet(int initialCapacity)
{
if (initialCapacity < 0)
throw new IllegalArgumentException
("initialCapacity is negative: " + initialCapacity);
data = new int[initialCapacity];
manyItems = 0;
}
public void ensureCapacity(int minimumCapacity)
{
int[ ] biggerArray;
if (data.length < minimumCapacity)
{
biggerArray = new int[minimumCapacity];
System.arraycopy(data, 0, biggerArray, 0, manyItems);
data = biggerArray;
}
}
public int getCapacity( )
{
return data.length;
}
public void trimToSize( )
{
int[ ] trimmedArray;
if (data.length != manyItems)
{
trimmedArray = new int[manyItems];
System.arraycopy(data, 0, trimmedArray, 0, manyItems);
data = trimmedArray;
}
}
public void add(int... elements)
{
if (manyItems + elements.length > data.length)
{ // Ensure twice as much space as we need.
ensureCapacity((manyItems + elements.length)*2);
}
for (int element : elements)
{
if ( ! this.contains(element) )
{
data[manyItems] = element;
manyItems++;
}
}
}
public void add(IntSet set2)
{
int[] arr = set2.toArray();
for( int element: arr)
{
if ( ! this.contains(element) )
{
this.add(element);
}
}
}
public void subtract(IntSet set2)
{
int[] arr = set2.toArray();
for (int element : arr)
{
if (this.contains(element) )
{
this.remove(element);
}
}
}
public void keepCommonElements(IntSet set2)
{
if (set2 != null)
{
int [] arr = set2. toArray();
for (int element: arr)
{
if(! this. contains(element))
{
this.remove(element);
}
}
}
}
public boolean contains(int target)
{
for (int n : data)
{
if( target == n)
{
return true;
}
}
return false;
}
public boolean remove(int target)
{
int index; // The location of target in the data array.
for (index = 0; (index < manyItems) && (target != data[index]); index++)
// No work is needed in the body of this for-loop.
;
if (index == manyItems)
// The target was not found, so nothing is removed.
return false;
else
{ // The target was found at data[index].
// So reduce manyItems by 1 and copy the last element onto data[index].
manyItems--;
data[index] = data[manyItems];
return true;
}
}
/**
* Determine the number of elements in this set.
* @return
* the number of elements in this set
*/
public int size( )
{
return manyItems;
}
/**
* Create a new set that contains all the elements from this set and the other set.
* @param set2
* the second set in the union
* @precondition
* set2 is not null, and
* getCapacity( ) + set2.getCapacity( ) <= Integer.MAX_VALUE.
* @return
* the union of this set and set2
* @exception NullPointerException
* Indicates that the argument is null.
* @exception OutOfMemoryError
* Indicates insufficient memory for the new set.
* @note
* An attempt to create a set with a capacity beyond
* Integer.MAX_VALUE will cause an arithmetic overflow
* that will cause the set to fail. Such large collections should use
* a different set implementation.
*/
public IntSet union(IntSet set2)
{
}
/**
* Create a new set that contains all the elements that are in both this set and the other set.
* @param set2
* the second set in the intersection
* @precondition
* set2 is not null
* @postcondition
* the returned set is smaller than either this set or set2
* @return
* the intersection of this set and set2
* @exception NullPointerException
* Indicates that the argument is null.
* @exception OutOfMemoryError
* Indicates insufficient memory for the new set.
*/
public IntSet intersection(IntSet set2)
{
// If set2 is null, then a NullPointerException is thrown.
}
/**
* Create a new set that contains all the elements from this set except those from the other set.
* @param set2
* the second set in the subtraction
* @precondition
* set2 is not null
* @postcondition
* the returned set is smaller than this set
* @return
* the subtraction of set2 from this set
* @exception NullPointerException
* Indicates that the argument is null.
* @exception OutOfMemoryError
* Indicates insufficient memory for the new set.
*/
public IntSet minus(IntSet set2)
{
}
public int[] toArray()
{
int[] arr = new int[this.size()]; //initialize the int array to store the set elements
for (int element : arr)
{
arr[element]= this.manyItems;
}
return arr; //return the int array
}
public String toString()
{
String result = "{";
for (int i = 0; i< this.size(); i++)
{
result +=" " + data[i];
//Add a comma after all but the last item
if (i < this.size()-1)
result += ",";
}
result += "}";
return result;
}
}//IntArraySet
Solution
The following are the methods for union, intersection and minus
public IntSet union(IntSet set2)
{
List array=new ArrayList();
for(int num:set2)
{
array.add(num);
}
for(int num:this)
{
array.add(num);
}
return array;
}
public IntSet intersection(IntSet set2)
{
// If set2 is null, then a NullPointerException is thrown.
int size=set2.size()+this.size();
List array=new ArrayList(size);
for(int num:set2)
{
if(this.contains(num))
{
array.add(num);
}
}
return array;
}
public IntSet minus(IntSet set2)
{
ArrayList array=new ArrayList();
array.add(this);
array.removeAll(set2);
return array;
}

More Related Content

Similar to Here is what I got so far, I dont know how to write union, interse.pdf

I need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdfI need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdffonecomp
 
public class DoubleArraySeq implements Cloneable {    Priva.pdf
public class DoubleArraySeq implements Cloneable {     Priva.pdfpublic class DoubleArraySeq implements Cloneable {     Priva.pdf
public class DoubleArraySeq implements Cloneable {    Priva.pdfannaimobiles
 
Part 1)#include stdio.h #include stdlib.h #include pthrea.pdf
Part 1)#include stdio.h #include stdlib.h #include pthrea.pdfPart 1)#include stdio.h #include stdlib.h #include pthrea.pdf
Part 1)#include stdio.h #include stdlib.h #include pthrea.pdfmohammadirfan136964
 
So I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfSo I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfaksahnan
 
Given the following errors and class in Java- How are these errors fix.pdf
Given the following errors and class in Java- How are these errors fix.pdfGiven the following errors and class in Java- How are these errors fix.pdf
Given the following errors and class in Java- How are these errors fix.pdfNicholasflqStewartl
 
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdfLabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdffantasiatheoutofthef
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfARCHANASTOREKOTA
 
Complete the class ArraySet1java which implements the SetA.pdf
Complete the class ArraySet1java which implements the SetA.pdfComplete the class ArraySet1java which implements the SetA.pdf
Complete the class ArraySet1java which implements the SetA.pdfabbecindia
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfmail931892
 
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdfHow do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdfmail931892
 
Modifications highlighted in bold lettersDropOutStack.javaim.pdf
Modifications highlighted in bold lettersDropOutStack.javaim.pdfModifications highlighted in bold lettersDropOutStack.javaim.pdf
Modifications highlighted in bold lettersDropOutStack.javaim.pdfLalkamal2
 
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxNew folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxcurwenmichaela
 
package lab7 public class SetOperations public static.pdf
package lab7     public class SetOperations  public static.pdfpackage lab7     public class SetOperations  public static.pdf
package lab7 public class SetOperations public static.pdfsyedabdul78662
 
How do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdfHow do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdffmac5
 
Java Foundations StackADT-java --- - Defines the interface to a stack.docx
Java Foundations StackADT-java ---  - Defines the interface to a stack.docxJava Foundations StackADT-java ---  - Defines the interface to a stack.docx
Java Foundations StackADT-java --- - Defines the interface to a stack.docxVictorXUQGloverl
 
@author Derek Harter @cwid 123 45 678 @class .docx
@author Derek Harter  @cwid   123 45 678  @class  .docx@author Derek Harter  @cwid   123 45 678  @class  .docx
@author Derek Harter @cwid 123 45 678 @class .docxadkinspaige22
 
Write a program that will test a name) method no sorting routine from.docx
 Write a program that will test a name) method no sorting routine from.docx Write a program that will test a name) method no sorting routine from.docx
Write a program that will test a name) method no sorting routine from.docxajoy21
 
Given the code below create a method called, getCollisionCount that .pdf
Given the code below create a method called, getCollisionCount that .pdfGiven the code below create a method called, getCollisionCount that .pdf
Given the code below create a method called, getCollisionCount that .pdfaucmistry
 
#ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf
 #ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf #ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf
#ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdfangelsfashion1
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdfakkhan101
 

Similar to Here is what I got so far, I dont know how to write union, interse.pdf (20)

I need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdfI need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdf
 
public class DoubleArraySeq implements Cloneable {    Priva.pdf
public class DoubleArraySeq implements Cloneable {     Priva.pdfpublic class DoubleArraySeq implements Cloneable {     Priva.pdf
public class DoubleArraySeq implements Cloneable {    Priva.pdf
 
Part 1)#include stdio.h #include stdlib.h #include pthrea.pdf
Part 1)#include stdio.h #include stdlib.h #include pthrea.pdfPart 1)#include stdio.h #include stdlib.h #include pthrea.pdf
Part 1)#include stdio.h #include stdlib.h #include pthrea.pdf
 
So I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfSo I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdf
 
Given the following errors and class in Java- How are these errors fix.pdf
Given the following errors and class in Java- How are these errors fix.pdfGiven the following errors and class in Java- How are these errors fix.pdf
Given the following errors and class in Java- How are these errors fix.pdf
 
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdfLabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdf
 
Complete the class ArraySet1java which implements the SetA.pdf
Complete the class ArraySet1java which implements the SetA.pdfComplete the class ArraySet1java which implements the SetA.pdf
Complete the class ArraySet1java which implements the SetA.pdf
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
 
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdfHow do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
 
Modifications highlighted in bold lettersDropOutStack.javaim.pdf
Modifications highlighted in bold lettersDropOutStack.javaim.pdfModifications highlighted in bold lettersDropOutStack.javaim.pdf
Modifications highlighted in bold lettersDropOutStack.javaim.pdf
 
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxNew folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
 
package lab7 public class SetOperations public static.pdf
package lab7     public class SetOperations  public static.pdfpackage lab7     public class SetOperations  public static.pdf
package lab7 public class SetOperations public static.pdf
 
How do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdfHow do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdf
 
Java Foundations StackADT-java --- - Defines the interface to a stack.docx
Java Foundations StackADT-java ---  - Defines the interface to a stack.docxJava Foundations StackADT-java ---  - Defines the interface to a stack.docx
Java Foundations StackADT-java --- - Defines the interface to a stack.docx
 
@author Derek Harter @cwid 123 45 678 @class .docx
@author Derek Harter  @cwid   123 45 678  @class  .docx@author Derek Harter  @cwid   123 45 678  @class  .docx
@author Derek Harter @cwid 123 45 678 @class .docx
 
Write a program that will test a name) method no sorting routine from.docx
 Write a program that will test a name) method no sorting routine from.docx Write a program that will test a name) method no sorting routine from.docx
Write a program that will test a name) method no sorting routine from.docx
 
Given the code below create a method called, getCollisionCount that .pdf
Given the code below create a method called, getCollisionCount that .pdfGiven the code below create a method called, getCollisionCount that .pdf
Given the code below create a method called, getCollisionCount that .pdf
 
#ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf
 #ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf #ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf
#ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdf
 

More from arihantpatna

Compare and contrast the advantages and disadvantages of arrays and .pdf
Compare and contrast the advantages and disadvantages of arrays and .pdfCompare and contrast the advantages and disadvantages of arrays and .pdf
Compare and contrast the advantages and disadvantages of arrays and .pdfarihantpatna
 
Answer and describe the following five plants habit, habitat, life .pdf
Answer and describe the following five plants habit, habitat, life .pdfAnswer and describe the following five plants habit, habitat, life .pdf
Answer and describe the following five plants habit, habitat, life .pdfarihantpatna
 
A plant has the genotype (Aa; Bb; Cc). How many different genotype.pdf
A plant has the genotype (Aa; Bb; Cc). How many different genotype.pdfA plant has the genotype (Aa; Bb; Cc). How many different genotype.pdf
A plant has the genotype (Aa; Bb; Cc). How many different genotype.pdfarihantpatna
 
A) Explain how bilateral symmetry contributed to motion and cephaliz.pdf
A) Explain how bilateral symmetry contributed to motion and cephaliz.pdfA) Explain how bilateral symmetry contributed to motion and cephaliz.pdf
A) Explain how bilateral symmetry contributed to motion and cephaliz.pdfarihantpatna
 
_______ are any substances that when introduced into the body, stimul.pdf
_______ are any substances that when introduced into the body, stimul.pdf_______ are any substances that when introduced into the body, stimul.pdf
_______ are any substances that when introduced into the body, stimul.pdfarihantpatna
 
You decide to spend Break hiking through the Rockies upon arrival, yo.pdf
You decide to spend Break hiking through the Rockies upon arrival, yo.pdfYou decide to spend Break hiking through the Rockies upon arrival, yo.pdf
You decide to spend Break hiking through the Rockies upon arrival, yo.pdfarihantpatna
 
Write a program in Java that reads a set of doubles from a file, sto.pdf
Write a program in Java that reads a set of doubles from a file, sto.pdfWrite a program in Java that reads a set of doubles from a file, sto.pdf
Write a program in Java that reads a set of doubles from a file, sto.pdfarihantpatna
 
Which of the following statements is true about cultureA. Culture.pdf
Which of the following statements is true about cultureA. Culture.pdfWhich of the following statements is true about cultureA. Culture.pdf
Which of the following statements is true about cultureA. Culture.pdfarihantpatna
 
Which data set has the least sample standard deviation Data set (ii.pdf
Which data set has the least sample standard deviation  Data set (ii.pdfWhich data set has the least sample standard deviation  Data set (ii.pdf
Which data set has the least sample standard deviation Data set (ii.pdfarihantpatna
 
Whats wrong with this Hardy Weinberg question I thought it was a.pdf
Whats wrong with this Hardy Weinberg question I thought it was a.pdfWhats wrong with this Hardy Weinberg question I thought it was a.pdf
Whats wrong with this Hardy Weinberg question I thought it was a.pdfarihantpatna
 
6. List and define the underlying conditions, or assumptions, which .pdf
6. List and define the underlying conditions, or assumptions, which .pdf6. List and define the underlying conditions, or assumptions, which .pdf
6. List and define the underlying conditions, or assumptions, which .pdfarihantpatna
 
What does the LP tableau below indicate (The xs are decision varia.pdf
What does the LP tableau below indicate (The xs are decision varia.pdfWhat does the LP tableau below indicate (The xs are decision varia.pdf
What does the LP tableau below indicate (The xs are decision varia.pdfarihantpatna
 
Wha is the difference between the large intestine and colon .pdf
Wha is the difference between the large intestine and colon .pdfWha is the difference between the large intestine and colon .pdf
Wha is the difference between the large intestine and colon .pdfarihantpatna
 
Was airpower decisive in winning World War II Defend your answer..pdf
Was airpower decisive in winning World War II Defend your answer..pdfWas airpower decisive in winning World War II Defend your answer..pdf
Was airpower decisive in winning World War II Defend your answer..pdfarihantpatna
 
Summarize the workflow of the study of microbial diversity. Draw a d.pdf
Summarize the workflow of the study of microbial diversity. Draw a d.pdfSummarize the workflow of the study of microbial diversity. Draw a d.pdf
Summarize the workflow of the study of microbial diversity. Draw a d.pdfarihantpatna
 
Shifting allocations most often arise as a result of which of the fo.pdf
Shifting allocations most often arise as a result of which of the fo.pdfShifting allocations most often arise as a result of which of the fo.pdf
Shifting allocations most often arise as a result of which of the fo.pdfarihantpatna
 
16.) How would you determine if Cellulous is hydrophobic or hydrophi.pdf
16.) How would you determine if Cellulous is hydrophobic or hydrophi.pdf16.) How would you determine if Cellulous is hydrophobic or hydrophi.pdf
16.) How would you determine if Cellulous is hydrophobic or hydrophi.pdfarihantpatna
 
Please Explain CompletelyWhat defines the beginning of the hepatic.pdf
Please Explain CompletelyWhat defines the beginning of the hepatic.pdfPlease Explain CompletelyWhat defines the beginning of the hepatic.pdf
Please Explain CompletelyWhat defines the beginning of the hepatic.pdfarihantpatna
 
Plant Diversity II –     Seed Plants1. Explain how the rise in pro.pdf
Plant Diversity II –     Seed Plants1. Explain how the rise in pro.pdfPlant Diversity II –     Seed Plants1. Explain how the rise in pro.pdf
Plant Diversity II –     Seed Plants1. Explain how the rise in pro.pdfarihantpatna
 
17) Fill out the following table Structure Pili or Fimbriae Flagella.pdf
17) Fill out the following table Structure Pili or Fimbriae Flagella.pdf17) Fill out the following table Structure Pili or Fimbriae Flagella.pdf
17) Fill out the following table Structure Pili or Fimbriae Flagella.pdfarihantpatna
 

More from arihantpatna (20)

Compare and contrast the advantages and disadvantages of arrays and .pdf
Compare and contrast the advantages and disadvantages of arrays and .pdfCompare and contrast the advantages and disadvantages of arrays and .pdf
Compare and contrast the advantages and disadvantages of arrays and .pdf
 
Answer and describe the following five plants habit, habitat, life .pdf
Answer and describe the following five plants habit, habitat, life .pdfAnswer and describe the following five plants habit, habitat, life .pdf
Answer and describe the following five plants habit, habitat, life .pdf
 
A plant has the genotype (Aa; Bb; Cc). How many different genotype.pdf
A plant has the genotype (Aa; Bb; Cc). How many different genotype.pdfA plant has the genotype (Aa; Bb; Cc). How many different genotype.pdf
A plant has the genotype (Aa; Bb; Cc). How many different genotype.pdf
 
A) Explain how bilateral symmetry contributed to motion and cephaliz.pdf
A) Explain how bilateral symmetry contributed to motion and cephaliz.pdfA) Explain how bilateral symmetry contributed to motion and cephaliz.pdf
A) Explain how bilateral symmetry contributed to motion and cephaliz.pdf
 
_______ are any substances that when introduced into the body, stimul.pdf
_______ are any substances that when introduced into the body, stimul.pdf_______ are any substances that when introduced into the body, stimul.pdf
_______ are any substances that when introduced into the body, stimul.pdf
 
You decide to spend Break hiking through the Rockies upon arrival, yo.pdf
You decide to spend Break hiking through the Rockies upon arrival, yo.pdfYou decide to spend Break hiking through the Rockies upon arrival, yo.pdf
You decide to spend Break hiking through the Rockies upon arrival, yo.pdf
 
Write a program in Java that reads a set of doubles from a file, sto.pdf
Write a program in Java that reads a set of doubles from a file, sto.pdfWrite a program in Java that reads a set of doubles from a file, sto.pdf
Write a program in Java that reads a set of doubles from a file, sto.pdf
 
Which of the following statements is true about cultureA. Culture.pdf
Which of the following statements is true about cultureA. Culture.pdfWhich of the following statements is true about cultureA. Culture.pdf
Which of the following statements is true about cultureA. Culture.pdf
 
Which data set has the least sample standard deviation Data set (ii.pdf
Which data set has the least sample standard deviation  Data set (ii.pdfWhich data set has the least sample standard deviation  Data set (ii.pdf
Which data set has the least sample standard deviation Data set (ii.pdf
 
Whats wrong with this Hardy Weinberg question I thought it was a.pdf
Whats wrong with this Hardy Weinberg question I thought it was a.pdfWhats wrong with this Hardy Weinberg question I thought it was a.pdf
Whats wrong with this Hardy Weinberg question I thought it was a.pdf
 
6. List and define the underlying conditions, or assumptions, which .pdf
6. List and define the underlying conditions, or assumptions, which .pdf6. List and define the underlying conditions, or assumptions, which .pdf
6. List and define the underlying conditions, or assumptions, which .pdf
 
What does the LP tableau below indicate (The xs are decision varia.pdf
What does the LP tableau below indicate (The xs are decision varia.pdfWhat does the LP tableau below indicate (The xs are decision varia.pdf
What does the LP tableau below indicate (The xs are decision varia.pdf
 
Wha is the difference between the large intestine and colon .pdf
Wha is the difference between the large intestine and colon .pdfWha is the difference between the large intestine and colon .pdf
Wha is the difference between the large intestine and colon .pdf
 
Was airpower decisive in winning World War II Defend your answer..pdf
Was airpower decisive in winning World War II Defend your answer..pdfWas airpower decisive in winning World War II Defend your answer..pdf
Was airpower decisive in winning World War II Defend your answer..pdf
 
Summarize the workflow of the study of microbial diversity. Draw a d.pdf
Summarize the workflow of the study of microbial diversity. Draw a d.pdfSummarize the workflow of the study of microbial diversity. Draw a d.pdf
Summarize the workflow of the study of microbial diversity. Draw a d.pdf
 
Shifting allocations most often arise as a result of which of the fo.pdf
Shifting allocations most often arise as a result of which of the fo.pdfShifting allocations most often arise as a result of which of the fo.pdf
Shifting allocations most often arise as a result of which of the fo.pdf
 
16.) How would you determine if Cellulous is hydrophobic or hydrophi.pdf
16.) How would you determine if Cellulous is hydrophobic or hydrophi.pdf16.) How would you determine if Cellulous is hydrophobic or hydrophi.pdf
16.) How would you determine if Cellulous is hydrophobic or hydrophi.pdf
 
Please Explain CompletelyWhat defines the beginning of the hepatic.pdf
Please Explain CompletelyWhat defines the beginning of the hepatic.pdfPlease Explain CompletelyWhat defines the beginning of the hepatic.pdf
Please Explain CompletelyWhat defines the beginning of the hepatic.pdf
 
Plant Diversity II –     Seed Plants1. Explain how the rise in pro.pdf
Plant Diversity II –     Seed Plants1. Explain how the rise in pro.pdfPlant Diversity II –     Seed Plants1. Explain how the rise in pro.pdf
Plant Diversity II –     Seed Plants1. Explain how the rise in pro.pdf
 
17) Fill out the following table Structure Pili or Fimbriae Flagella.pdf
17) Fill out the following table Structure Pili or Fimbriae Flagella.pdf17) Fill out the following table Structure Pili or Fimbriae Flagella.pdf
17) Fill out the following table Structure Pili or Fimbriae Flagella.pdf
 

Recently uploaded

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
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
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
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
 
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
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 

Recently uploaded (20)

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
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
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
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
 
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
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 

Here is what I got so far, I dont know how to write union, interse.pdf

  • 1. Here is what I got so far, I don't know how to write union, intersection, and minus. Please complete this code in Java. do not use iterator public class IntArraySet extends IntSet { private int[ ] data; private int manyItems; public IntArraySet( ) { final int INITIAL_CAPACITY = 10; manyItems = 0; data = new int[INITIAL_CAPACITY]; } public IntArraySet(int initialCapacity) { if (initialCapacity < 0) throw new IllegalArgumentException ("initialCapacity is negative: " + initialCapacity); data = new int[initialCapacity]; manyItems = 0; } public void ensureCapacity(int minimumCapacity) { int[ ] biggerArray; if (data.length < minimumCapacity) { biggerArray = new int[minimumCapacity]; System.arraycopy(data, 0, biggerArray, 0, manyItems); data = biggerArray; } } public int getCapacity( ) { return data.length;
  • 2. } public void trimToSize( ) { int[ ] trimmedArray; if (data.length != manyItems) { trimmedArray = new int[manyItems]; System.arraycopy(data, 0, trimmedArray, 0, manyItems); data = trimmedArray; } } public void add(int... elements) { if (manyItems + elements.length > data.length) { // Ensure twice as much space as we need. ensureCapacity((manyItems + elements.length)*2); } for (int element : elements) { if ( ! this.contains(element) ) { data[manyItems] = element; manyItems++; } } } public void add(IntSet set2) { int[] arr = set2.toArray(); for( int element: arr) { if ( ! this.contains(element) ) { this.add(element);
  • 3. } } } public void subtract(IntSet set2) { int[] arr = set2.toArray(); for (int element : arr) { if (this.contains(element) ) { this.remove(element); } } } public void keepCommonElements(IntSet set2) { if (set2 != null) { int [] arr = set2. toArray(); for (int element: arr) { if(! this. contains(element)) { this.remove(element); } } } } public boolean contains(int target) { for (int n : data)
  • 4. { if( target == n) { return true; } } return false; } public boolean remove(int target) { int index; // The location of target in the data array. for (index = 0; (index < manyItems) && (target != data[index]); index++) // No work is needed in the body of this for-loop. ; if (index == manyItems) // The target was not found, so nothing is removed. return false; else { // The target was found at data[index]. // So reduce manyItems by 1 and copy the last element onto data[index]. manyItems--; data[index] = data[manyItems]; return true; } } /** * Determine the number of elements in this set. * @return * the number of elements in this set */ public int size( ) { return manyItems;
  • 5. } /** * Create a new set that contains all the elements from this set and the other set. * @param set2 * the second set in the union * @precondition * set2 is not null, and * getCapacity( ) + set2.getCapacity( ) <= Integer.MAX_VALUE. * @return * the union of this set and set2 * @exception NullPointerException * Indicates that the argument is null. * @exception OutOfMemoryError * Indicates insufficient memory for the new set. * @note * An attempt to create a set with a capacity beyond * Integer.MAX_VALUE will cause an arithmetic overflow * that will cause the set to fail. Such large collections should use * a different set implementation. */ public IntSet union(IntSet set2) { } /** * Create a new set that contains all the elements that are in both this set and the other set. * @param set2 * the second set in the intersection * @precondition * set2 is not null * @postcondition
  • 6. * the returned set is smaller than either this set or set2 * @return * the intersection of this set and set2 * @exception NullPointerException * Indicates that the argument is null. * @exception OutOfMemoryError * Indicates insufficient memory for the new set. */ public IntSet intersection(IntSet set2) { // If set2 is null, then a NullPointerException is thrown. } /** * Create a new set that contains all the elements from this set except those from the other set. * @param set2 * the second set in the subtraction * @precondition * set2 is not null * @postcondition * the returned set is smaller than this set * @return * the subtraction of set2 from this set * @exception NullPointerException * Indicates that the argument is null. * @exception OutOfMemoryError * Indicates insufficient memory for the new set. */ public IntSet minus(IntSet set2) { }
  • 7. public int[] toArray() { int[] arr = new int[this.size()]; //initialize the int array to store the set elements for (int element : arr) { arr[element]= this.manyItems; } return arr; //return the int array } public String toString() { String result = "{"; for (int i = 0; i< this.size(); i++) { result +=" " + data[i]; //Add a comma after all but the last item if (i < this.size()-1) result += ","; } result += "}"; return result; } }//IntArraySet Solution The following are the methods for union, intersection and minus public IntSet union(IntSet set2) { List array=new ArrayList(); for(int num:set2) { array.add(num); } for(int num:this)
  • 8. { array.add(num); } return array; } public IntSet intersection(IntSet set2) { // If set2 is null, then a NullPointerException is thrown. int size=set2.size()+this.size(); List array=new ArrayList(size); for(int num:set2) { if(this.contains(num)) { array.add(num); } } return array; } public IntSet minus(IntSet set2) { ArrayList array=new ArrayList(); array.add(this); array.removeAll(set2); return array; }