Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Copy the program below and edit the code within the boundary that I specified so that it matches the output indicated in the screenshot. The

Copy the program below and edit the code within the boundary that I specified so that it matches the output indicated in the screenshot. The left of the screenshot is what the output needs to be and the right is what the output currently is.image text in transcribed

To get a thumbs up:

-Match outputs (Left of the screenshot is what it needs to be)

-Write the public void remove(Object obj) {

} method (description of it is in the comment block right above the method)

_____________________________________________________________________________________

COPY THIS:

package myset;

import java.util.Arrays; /** * This Java application implements a Set data structure * that stores a set of Objects. MySet objects have a fixed * capacity (i.e. they don't grow) and duplicate members * are not allowed. * */

interface CSC205_Set { boolean isMember(Object obj); boolean isEmpty(); boolean isFull(); int capacity(); int size(); void clear(); String toString(); int add(Object obj); void remove(Object obj); boolean equals(MySet that); MySet union(MySet that); MySet intersection(MySet that); MySet difference(MySet that); }

public class MySet implements CSC205_Set {

public static final int ADD_DUP_ERRNO = -1; public static final int ADD_FULL_ERRNO = -2;

private static final int CAPACITY = 7;

private Object[] data; private int size;

/** * Constructs a MySet object having a default CAPACITY. */ public MySet() { this(CAPACITY); }

/** * Constructs a MySet object having a client supplied capacity. * * @param capacity becomes CAPACITY if

/** * Constructs a MySet object containing Integer objects. * * @param e int[] of values that get added to this MySet */ public MySet(int[] e) { data = new Object[CAPACITY]; size = e.length > CAPACITY ? CAPACITY : e.length; for (int i = 0; i

/** * Checks to see of an object is a member of this MySet. * * @param obj the class Object object to search for * @return true if object is a member of this MySet * @return false if object is not a member of this MySet */ public boolean isMember(Object obj) { for (int i = 0; i

/** * Checks to see if this MySet has zero members (elements). * * @return true if this MySet has zero members * @return false if this MySet has more than zero members */ public boolean isEmpty() { return size == 0; }

/** * Checks to see if this MySet is at capacity. * * @return true if at capacity * @return false if not at capacity */ public boolean isFull() { return size == data.length; }

/** * Returns the number of members in this MySet. * * @return number of members in this MySet */ public int size() { return size; }

/** * An alias for size(). * * @return number of members */ public int cardinality() { return size; }

/** * Getter method so client can check the capacity of this MySet. * * @return capacity of this MySet */ public int capacity() { return data.length; }

/** * Sets the size of this MySet to zero. */ public void clear() { size = 0; }

/** * Constructs a String representation of this MySet. * * @return string representation of this MySet */ public String toString() { StringBuffer sb = new StringBuffer("{"); int n = size - 1; for (int i = 0; i 0) sb.append(data[n]); return new String(sb) + "}"; } //***************************ONLY EDIT THE CODE BELOW THIS BOUNDARY*********** /* * TBI (To Be Implemented) -- The remaining instance methods * need to be implemented as part of the #Set assignment. */

/** * TBI (To Be Implemented) * Adds an object to this MySet. * * @param obj the class Object to add to this MySet * @return ADD_FULL_ERRNO if this MySet is at capacity; * else return ADD_DUP_ERRNO if object already * a member of this MySet; else return the new * size of this MySet */ public int add(Object obj) { int i=contains(obj); if (i==-1) { if (data.length - size

public void reSizeArray() { data = Arrays.copyOf(data, data.length + 1); }

public int contains(Object elem){ if (elem == null) { for (int i = 0; i

/** * TBI (To Be Implemented) * Removes an object from this MySet. The method does nothing * if the object is not a member. * * @param obj the object to remove from this MySet */ public void remove(Object obj) { }

/** * TBI (To Be Implemented) * Checks to see if two MySet objects are equal. * hint: a.difference(b) and b.difference(a) * are both empty, then... * * @param that MySet to compare again this MySet * @return true if the two MySets are equal; else * return false */ public boolean equals(MySet that) { if (size()==that.size) { for (int i = 0; i

/** * TBI (To Be Implemented) * Instantiates a new MySet object that contains all of the elements * of this MySet and all of the elements of that MySet (duplicates * are not allowed). * * @param that MySet to do union with this MySet * @return the union of this and that MySets */ public MySet union(MySet that) { for(int i = 0; i

}

/** * TBI (To Be Implemented) * Instantiates a new MySet object that contains all of the * members that are found in both this MySet and that MySet. * * @param that MySet to do intersection with this MySet * @return the intersection of this and that MySets */ public MySet intersection(MySet that) { MySet newSet = new MySet(); int smallSize = 0; for(int i = 0; i

}

/** * TBI (To Be Implemented) * Instantiates a new MySet object that contains all of the * members of this MySet that are not found in that MySet. * * @param that MySet to do difference with this MySet * @return the difference of this and that MySets */ public MySet difference(MySet that) { MySet newSet = new MySet(); for(int i = 0; i

//***************************ONLY EDIT THE CODE ABOVE THIS BOUNDARY*********** /** * The main() method is used exclusively for testing. */ public static void main(String[] argv) { Object[] objects = { new Integer(205), new String("Java supports OOP"), new Boolean(true), new Byte((byte)42), new Integer(240), new Byte((byte)42), new String("foo"), new Boolean(true), new String("foo"), new String("Java creator: James Gosling"), new Integer(240), new Double(3.14159265), new Object(), };

MySet test = new MySet();

for (int i = 0; i

final String SEPARATOR = " ========================="; System.out.println(SEPARATOR);

final int[] A = { 5, 7, 3, 2 }; final int[] B = { 2, 6 }; final int[] C = { 1, 2, 5 }; final int[] D = { 3, 2, 7, 5 }; final int[] E = { 5, 2, 1 };

MySet a = new MySet(A); System.out.println("A: " + a); MySet b = new MySet(B); System.out.println("B: " + b); MySet c = new MySet(C); System.out.println("C: " + c); MySet d = new MySet(D); System.out.println("D: " + d); MySet e = new MySet(E); System.out.println("E: " + e);

System.out.println(a + ".equals(" + b + ") is " + a.equals(b)); System.out.println(c + ".equals(" + d + ") is " + c.equals(d)); System.out.println(c + ".equals(" + e + ") is " + c.equals(e));

System.out.println(a + ".union(" + b + "): " + a.union(b)); System.out.println(a + ".intersection(" + b + "): " + a.intersection(b)); System.out.println(a + ".difference(" + b + "): " + a.difference(b)); System.out.println(b + ".difference(" + a + "): " + b.difference(a));

System.out.println(c + ".union(" + d + "): " + c.union(d)); System.out.println(c + ".intersection(" + d + "): " + c.intersection(d)); System.out.println(c + ".difference(" + d + "): " + c.difference(d)); System.out.println(d + ".difference(" + c + "): " + d.difference(c)); System.out.println(c + ".difference(" + e + "): " + c.difference(e));

System.out.println(a + ".union(" + a + "): " + a.union(a)); System.out.println(a + ".intersection(" + a + "): " + a.intersection(a)); System.out.println(a + ".difference(" + a +"): " + a.difference(a));

Integer x = new Integer(A[1]); System.out.print(a); a.remove(x); System.out.println(".remove(" + x + "): " + a); // miscelleanous testing... MySet n0 = new MySet(); MySet n1 = new MySet(); System.out.println(n0 + ".union(" + n1 + "): " + n0.union(n1)); System.out.println(n0 + ".intersection(" + n1 + "): " + n0.intersection(n1)); System.out.println(n0 + ".difference(" + n1 + "): " + n0.difference(n1)); System.out.println(n0 + ".union(" + a + "): " + n0.union(a)); System.out.println(n0 + ".intersection(" + a + "): " + n0.intersection(a)); System.out.println(n0 + ".difference(" + a + "): " + n0.difference(a)); System.out.println(a + ".union(" + n0 + "): " + a.union(n0)); System.out.println(a + ".intersection(" + n0 + "): " + a.intersection(n0)); System.out.println(a + ".difference(" + n0 + "): " + a.difference(n0)); }

private static void dump(MySet set) { System.out.println("...isEmpty(): " + set.isEmpty() + "; isFull(): " + set.isFull() + "; size(): " + set.size() + "; capacity(): " + set.capacity()); } }

Java supports UOP added ?21 42 not added bic it's a duplicate true not added bfc it's a duplicate fon not added hfc st's a duplicate Java creator: Janes Gosling added (7} java. lang . Object)7852e322 dded {9) (285, ]ava supports nop, true, 42, 240, fno? ]ava creator ! janes Gasling. 3.14159265, java. tang. nbjectp7852e022) isEnptyi: Talse: isFullo: false: sie) 9: capacityl 12 1sLnptyn: true ; 1sfullW: false; sizell: e; capacity! :: 12 240 not addod bie test i luil 3-141S5265 ae added b/c test ia Eull (5, 7, 3, 21.equals2, 6 is false 1, 2, eual3, 2, ,5 is false 1, 2, 3.equals5, 2, 1 i5 true (5, 7, 3, 2),unaon ' {2,?): {2, 6, 5, 7, 3, null} (5, 7. 3,intersectinn(i2, 6, 5. 7. 3. null): iS, 7, 3. 2, nully (5, 7, 3, 21.diferencel(2, 6, 5, 7, 3, null3 ) (2, 6, , 7, 3, nullh.differencel(s, , 3, 211: (6 ?1, 2, 5}.unaon 3, 2, 7, 5}): {3, 2, 7, 5. 1' null} 1, 2, .intersection(13, 2. 7. 5. 1. nulH: ii. 2, 5. null 1, 2, 5.difterencel3, 2, 7. 5. 1, null (3, 2, 7, 5, 1, nu.differencel(1, 2, 5)1: (3, 7) (1, 2, 5),difference {{>, z, 11: {? (5, 7, 3, 2),unaon1{57,3,2): {57,3,2. null} 5, 7. 3, 2, nutl.intersection(5, 7. 3. 2. nulh) , z, 11: {? (5, 7, 3, 2),unaon1{57,3,2): {57,3,2. null} 5, 7. 3, 2, nutl.intersection(5, 7. 3. 2. nulh)

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

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

0132742926, 978-0132742924

More Books

Students also viewed these Databases questions

Question

Explain the issues of safety unique to small businesses.

Answered: 1 week ago

Question

Describe downsizing.

Answered: 1 week ago

Question

Discuss compensation for contingent workers.

Answered: 1 week ago