Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CAN SOMEONE PLEASE SOLVE THE ERRORS IN THIS CODE? AND UPLOAD IT AGAIN...SOLVED public class IntegerSet { // The array that represents the set. private

CAN SOMEONE PLEASE SOLVE THE ERRORS IN THIS CODE? AND UPLOAD IT AGAIN...SOLVED

public class IntegerSet {

// The array that represents the set.

private final int set[];

/**

* The constructor for IntegerSet. When an IntegerSet is created it must be

* initialized with an integer array. The set will then pull out the duplicated

* items and keep the unique integers.

*

* @param arr

* The array to create the set from.

*/

public IntegerSet(int arr[]) {

if (arr == null) {

throw new IllegalArgumentException("The array must not be null");

}

set = uniqueElements(arr);

}

/**

* This is the size of the set which, in this case, is just the length of the

* array.

*

* @return The length of the set.

*/

public int magnitude() {

return set.length; }

/**

* This method is private and is used to help set up the set array. An integer

* set is one in which the elements are unique (no duplicates) and are sorted.

*

* @param arr

* The array that will be used to retrieve the unique elements from.

* @return The new integer array that contains the unique elements from arr.

*/

private int[] uniqueElements(int arr[]) {

IntegerSet(int list[]){

int uniqueList[] = new int[list.length];

int uniqueCount=0;

boolean found=false;

for(int i=0;i

} else{ uniqueList[uniqueCount] = list[i]; uniqueCount++; }

} uniqueSet = new int[uniqueCount]; for(int i=0;i

}

for(int i=0;i

for(int j=i+1;j

if(uniqueSet[i]>uniqueSet[j]){

int temp = uniqueSet[i];

uniqueSet[i] = uniqueSet[j];

uniqueSet[j] = temp;

}

}

}

}

void printSet(){

for(int i=0;i

System.out.print(uniqueSet[i]+" ");

}

System.out.println();

}

return null; }

/** * This method returns whether or not value is located in the set. If the value * is in the set then return true otherwise return false.
* Example: *

 * IntegerSet iS1 = new IntegerSet([1,2,3,4]); * iS1.contains(3); //returns true * iS2.contains(6); //returns false * 
* * @param value * The integer to look for. * @return True if value is located in the set otherwise false. */ public boolean contains(int value) { for(int i=0;i

if(uniqueSet[i]==number){

return true;

}

}

return false; }

/** * A union of two sets is a new set that contains all elements from both sets. * This method takes another set and unions it with the set that calls this * method. A new IntegerSet is returned that contains the union of both sets.
* Example: *

 * IntegerSet is1 = new IntegerSet([1, 2, 3, 4]); * IntegerSet is2 = new IntegerSet([3, 4, 5, 6, 7, 8]); * is1.union(is2) //returns new IntegerSet([1, 2, 3, 4, 5, 6, 7, 8]); * 
* * @param otherSet * The set to be unioned with. * @return A new IntegerSet that is the union of the calling set with the * otherSet. */ public IntegerSet union(IntegerSet otherSet) { IntegerSet temp = new IntegerSet(); for ( int count = 0; count < 101; count++ ) temp.set[ count ] = ( set[ count ] || integerSet.set[ count ] ); return temp; }

/** * The intersection of two sets is a new set that contains elements that occur * in both sets. This method takes another set and intersects it with the set * that calls this method. A new IntegerSet is returned that contains the * intersection of the two sets.
* Example: *

 * IntegerSet is1 = new IntegerSet([1,2,3,4]); * IntegerSet is2 = new IntegerSet([3,4,5]); * is1.intersection(is2) //returns new IntegerSet([3, 4]); * 
* * @param otherSet * The set to be intersected with. * @return A new IntegerSet that is the intersection of the calling set with the * otherSet. */ public IntegerSet intersection(IntegerSet otherSet) { IntegerSet temp = new IntegerSet(); for ( int count = 0; count < 101; count++ ) temp.set[ count ] = ( set[ count ] && integerSet.set[ count ] ); return temp; }

/** * Returns a string representation of an IntegerSet type. The returned string * will have the following structure. * * set{ elements in the set separated by a comma }. */ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("set{ "); for (int i = 0; i < set.length; i++) { sb.append(set[i]); if (i < set.length - 1) { sb.append(", "); } } sb.append(" }"); return sb.toString(); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Filing And Computer Database Projects

Authors: Jeffrey Stewart

2nd Edition

007822781X, 9780078227813

More Books

Students also viewed these Databases questions

Question

=+What would happen to wages?

Answered: 1 week ago