For the method equals that you are to implement in ArraySetWithArray class for Project2 of Lab02:
- show steps that the method must follow to decide that two bags are equal
- show steps that the method must follow to decide that two bags are NOT equal
- use the scenarios from the main
- use your own scenarios
Checks if the given set called other is the same as this set
*
* @param o the other set to be compared with
* @return true both sets are the same
*/
public boolean equals(Object o)
{
boolean same;
if (this == o)
same = true;
else if (o == null || getClass() != o.getClass())
same = false;
else
{
ArraySetWithArray otherSet = (ArraySetWithArray) o;
//TODO Project2
// do not call toArray as you have direct access to setOfEntries
// one return statement per method please
// first compare number of entries in both sets
// only if the number of entries is the same
// use a regular for loop to compare elements
// stop the loop as soon as the first unequal pair is found
}
return false; // THIS IS A STUB
}
* Creates an empty array having a given initial capacity. For the following methods that you are to implement in Arca SetWithArrax class for Project2 of Lab02: removeMas, removeAllLarger, replace, union, intersection, difference, getAllLess Than, moveFirstToEnd + @param capacity The integer capacity desired. *7 o public BccaySetWithbcraujintcapacity) draw memory diagrams showing how the respective bags will look like as the result of the given method call use the scenarios from the main o use your own scenarios (Ctrl) - mpartiala utilarraus; { //TODO Project2 #3 }// end constructor /** * A class that implements the ADT set by using a resizable array. * Creates an array containing given en tries, The array is never full . . * @param contents an array of objects. * @author YOUR NAME @version 2/9/2021 public AccavSetWithocaval contents, int numberOfEntries) */ { public class ArcavSetWithBccay
> implements Setlotertasest> //TODO Project2 #6 { // calls this add not to allow null or duplicated elements // TODO Project2 #1 1/ open ResizableArrayBag in the split editor window }// end constructor // the implementation of Buray SetWithcray methods will be similar * Throws an exception if the client requests a capacity that is too large. private Il setOfEntries */ private int number of stules private boolean initialized; private void checkCapadtuin tcapacity) { private static final int DEFAULT_CAPACITY = 3; // Initial capacity of array private static final intMAX_CAPACITY = 100; if (capacity > MAX_CAPACTY) throw newlllesalStateException/"Attempt to create a set whose capacity exceeds"+ "allowed maximum of "+ MAX_CAPACITY); /** }// end checkCapacity Creates an empty array whose initial capacity is DEFAULT_CAPACITY */ public BucavSetWithcrawl { * Throws an exception if receiving objectis not initialized. //TODO Project2 #2 }// end default constructor private void sbeckInitialization) { if (this initialized) /** throw new SecurityException/"U ninitialized object used" + /** "to call an ArcaySetWithacay method."); + Sees whether this array is empty + } // end checkloitialization * @return True if this array is empty, or false if not. * Adds a new entry to this array, rejecting duplicates and null entries. public booleanisEmpty!) { + * @param DewEncy The object to be added as a new entry. * @return true if the addition is successful, or //TODO Project2 return false; //THISISA STUB + false in case of null entry or duplicate to be added. }//end is met +/ public boolean add newEnter) { * Gets the number of entries currently in this array, //TODO Project2#4 return false; //THISIS A STUB * @return. The integer number of entries currently in the array. }// end add */ public int getCurrentSzel) { - Checks if the set is full; if it is full doubles its size //TODO Project2 return 0; //THIS IS A STUB }//end getCurrentSze private void eosureCapacity) { //TODO Project2#4 }// end ensureCapacity * Tests whether this array contains a given entry. + * @param anEntry The entry to locate. + Retrieves all entries that are in this array. * @return True if the array contains anEntry, or false if not. +/ + * @return A newly allocated array of all the entries. public boolean contains TapEntry) */ { public Ill toscay() //TODO Project2 { //TODO Project2 // utilize getindexOf method return false; //THISIS A STUB return null; //THIS ISA STUB }// end toscray }// end contains - Locates a given entry within the array set. * @param anEntry The entry to be removed. + Returns the index of the entry, if located, * @return true if the removal was successful, or false if not. + or -1 otherwise, */ * Precondition: checkinitialization has been called. public booleanremoveElement TanEoty) { */ private int getIndexOfTaoEo //TODO Project2 { return false; //THISIS A STUB int index=1 }// end removeElement // TODO Project2 return index * Removes and returns the array entry at a given index. 1// end getIndexOf * @param glxeolodex index of the element to be removed * @return remove an element or null if no such entry exists + Removes all entries from this array. */ */ public void clear() private TremoueEnter{int givenlodex) { { //TODO Project2 return null; //THIS ISA STUB { //TODO Project2 } // end clear }// end removeEntex // *Removes one unspecified entry from this set. // +++++++++++++++++++ NEW METHODS ++++++++++++++++ ++++++ + @return Either the removed entry if the removal * was successful, or nullit not. /* +/ * Displays all entries in the set. public Tremoved) * If the set is empty displays a message that the set is empty and display the capacity { * if the set is not empty displays the number of elements, capacity and the content of the set //TODO Project2 */ return null; //THIS ISA STUB public void displayset) }// end remove { //TODO Project2#5 // do not call toscay since you have direct access to this setofeotriesarray } // end displayset + Removes one occurrence of a given entry from this array public TremgyeMax() { - Checks if the given set called other is the same as this set // TODO Project2 + // utilizeremoveEntex.cgiyenindex) method // one return statement per method please * @param o the other set to be compared with * @return true both sets are the same // utilize compare to method +7 return null; // THIS IS A STUB public boolean equals Object o) { }// end removeMax boolean same; if(this ==0) same = true: * Removes all entries from this set teotries that are larger than a given entry. else if(o== null || getClass() != 0.getClassi) same = false; @param a otcy the entry to be checked against */ else { public void removeall argerTapEntry) { // TODO Project2 ArcarsetWithcay other set= (AccarsetWithscrayja //TODO Project2 // do not call to Acay as you have direct access to setOfEntries /Lone return statement per method please // must utilize only one loop that starts with the last element Lutilize removeEntergivenlodex) method /L utilize compare to method // first compare number of entries in both sets // only if the number of entries is the same }// end removeAllLarger // use a regular for loop to compare elements // stop the loop as soon as the first unequal pair is found /*+ } * Replaces the last entry in this setQfEntries with a given object. + return false;//THIS IS A STUB } } * @param replacement the given object * @return the original entry in the setOfEntries that was replaced or null if the set is empty or if the replacement is a duplicate + */ * Removes the largest entry from the this setOfEntries public Treplace(Treplacement) { * @return- null if the set is empty // TODO Project2 or the largest element // do not call add or remove + Creates a new set of objects that would be left in this set return null; // THISIS A STUB * after removing those that also occur in a second given set 1 // end replace * without affecting the original two sets. * @param obec Set the given set * Creates a new set that combines the contents of this set and @return a set that is the difference of the two sets * a second given set without affecting the original two sets. public AlcaySetWithAccarsT> difference[ercaySetWithArray other seu { * @param atberSet the given set * @return a setOfEntries that is the union of the two sets // TODO Project2 // one return statement per method please public AlcaySetWithscayunionAccaySetWithAccay otherseu { return null; // THIS IS A STUB // TODO Project2 } // end difference Lone return statement per method please /** return null; // THIS IS A STUB * Creates a new set of objects that are in this set and are less than a given object. + } // end union * @param a Entry a given object * @return a new set of objects that are in this set and are less than a Obiect * Creates a new set that contains those objects that occur in both this * set and other set without affecting the original two sets. public ArcasetwitharcayT>getAlll pss Than TanEntry) { * @param other set the given set // TODO Project2 * @return a set that is the intersection of the two sets // one return statement per method please +/ Lutilize compare to method public AccarsetWithocay intersection ArcasetWithArrayotberset { return null; // THIS IS A STUB // TODO Project2 } // end getAllLess Than // one return statement per method please * Checks if all the elements of the given set are also included in the other set return null; // THIS IS A STUB }// end intersection * @param other set set to check ----------- Il L -------- -------------- public boolean issubsetaccarsetwithstarotberset { // TODO Project2 /Lone return statement per method please 11 utilize difference method return false;//THIS IS A STUB } * Move the first element to be the last in the set by rotating the elements public void nooreFirstToEnd) { // TODO Project2 1L do not call add or remove } * Creates an empty array having a given initial capacity. For the following methods that you are to implement in Arca SetWithArrax class for Project2 of Lab02: removeMas, removeAllLarger, replace, union, intersection, difference, getAllLess Than, moveFirstToEnd + @param capacity The integer capacity desired. *7 o public BccaySetWithbcraujintcapacity) draw memory diagrams showing how the respective bags will look like as the result of the given method call use the scenarios from the main o use your own scenarios (Ctrl) - mpartiala utilarraus; { //TODO Project2 #3 }// end constructor /** * A class that implements the ADT set by using a resizable array. * Creates an array containing given en tries, The array is never full . . * @param contents an array of objects. * @author YOUR NAME @version 2/9/2021 public AccavSetWithocaval contents, int numberOfEntries) */ { public class ArcavSetWithBccay> implements Setlotertasest> //TODO Project2 #6 { // calls this add not to allow null or duplicated elements // TODO Project2 #1 1/ open ResizableArrayBag in the split editor window }// end constructor // the implementation of Buray SetWithcray methods will be similar * Throws an exception if the client requests a capacity that is too large. private Il setOfEntries */ private int number of stules private boolean initialized; private void checkCapadtuin tcapacity) { private static final int DEFAULT_CAPACITY = 3; // Initial capacity of array private static final intMAX_CAPACITY = 100; if (capacity > MAX_CAPACTY) throw newlllesalStateException/"Attempt to create a set whose capacity exceeds"+ "allowed maximum of "+ MAX_CAPACITY); /** }// end checkCapacity Creates an empty array whose initial capacity is DEFAULT_CAPACITY */ public BucavSetWithcrawl { * Throws an exception if receiving objectis not initialized. //TODO Project2 #2 }// end default constructor private void sbeckInitialization) { if (this initialized) /** throw new SecurityException/"U ninitialized object used" + /** "to call an ArcaySetWithacay method."); + Sees whether this array is empty + } // end checkloitialization * @return True if this array is empty, or false if not. * Adds a new entry to this array, rejecting duplicates and null entries. public booleanisEmpty!) { + * @param DewEncy The object to be added as a new entry. * @return true if the addition is successful, or //TODO Project2 return false; //THISISA STUB + false in case of null entry or duplicate to be added. }//end is met +/ public boolean add newEnter) { * Gets the number of entries currently in this array, //TODO Project2#4 return false; //THISIS A STUB * @return. The integer number of entries currently in the array. }// end add */ public int getCurrentSzel) { - Checks if the set is full; if it is full doubles its size //TODO Project2 return 0; //THIS IS A STUB }//end getCurrentSze private void eosureCapacity) { //TODO Project2#4 }// end ensureCapacity * Tests whether this array contains a given entry. + * @param anEntry The entry to locate. + Retrieves all entries that are in this array. * @return True if the array contains anEntry, or false if not. +/ + * @return A newly allocated array of all the entries. public boolean contains TapEntry) */ { public Ill toscay() //TODO Project2 { //TODO Project2 // utilize getindexOf method return false; //THISIS A STUB return null; //THIS ISA STUB }// end toscray }// end contains - Locates a given entry within the array set. * @param anEntry The entry to be removed. + Returns the index of the entry, if located, * @return true if the removal was successful, or false if not. + or -1 otherwise, */ * Precondition: checkinitialization has been called. public booleanremoveElement TanEoty) { */ private int getIndexOfTaoEo //TODO Project2 { return false; //THISIS A STUB int index=1 }// end removeElement // TODO Project2 return index * Removes and returns the array entry at a given index. 1// end getIndexOf * @param glxeolodex index of the element to be removed * @return remove an element or null if no such entry exists + Removes all entries from this array. */ */ public void clear() private TremoueEnter{int givenlodex) { { //TODO Project2 return null; //THIS ISA STUB { //TODO Project2 } // end clear }// end removeEntex // *Removes one unspecified entry from this set. // +++++++++++++++++++ NEW METHODS ++++++++++++++++ ++++++ + @return Either the removed entry if the removal * was successful, or nullit not. /* +/ * Displays all entries in the set. public Tremoved) * If the set is empty displays a message that the set is empty and display the capacity { * if the set is not empty displays the number of elements, capacity and the content of the set //TODO Project2 */ return null; //THIS ISA STUB public void displayset) }// end remove { //TODO Project2#5 // do not call toscay since you have direct access to this setofeotriesarray } // end displayset + Removes one occurrence of a given entry from this array public TremgyeMax() { - Checks if the given set called other is the same as this set // TODO Project2 + // utilizeremoveEntex.cgiyenindex) method // one return statement per method please * @param o the other set to be compared with * @return true both sets are the same // utilize compare to method +7 return null; // THIS IS A STUB public boolean equals Object o) { }// end removeMax boolean same; if(this ==0) same = true: * Removes all entries from this set teotries that are larger than a given entry. else if(o== null || getClass() != 0.getClassi) same = false; @param a otcy the entry to be checked against */ else { public void removeall argerTapEntry) { // TODO Project2 ArcarsetWithcay other set= (AccarsetWithscrayja //TODO Project2 // do not call to Acay as you have direct access to setOfEntries /Lone return statement per method please // must utilize only one loop that starts with the last element Lutilize removeEntergivenlodex) method /L utilize compare to method // first compare number of entries in both sets // only if the number of entries is the same }// end removeAllLarger // use a regular for loop to compare elements // stop the loop as soon as the first unequal pair is found /*+ } * Replaces the last entry in this setQfEntries with a given object. + return false;//THIS IS A STUB } } * @param replacement the given object * @return the original entry in the setOfEntries that was replaced or null if the set is empty or if the replacement is a duplicate + */ * Removes the largest entry from the this setOfEntries public Treplace(Treplacement) { * @return- null if the set is empty // TODO Project2 or the largest element // do not call add or remove + Creates a new set of objects that would be left in this set return null; // THISIS A STUB * after removing those that also occur in a second given set 1 // end replace * without affecting the original two sets. * @param obec Set the given set * Creates a new set that combines the contents of this set and @return a set that is the difference of the two sets * a second given set without affecting the original two sets. public AlcaySetWithAccarsT> difference[ercaySetWithArray other seu { * @param atberSet the given set * @return a setOfEntries that is the union of the two sets // TODO Project2 // one return statement per method please public AlcaySetWithscayunionAccaySetWithAccay otherseu { return null; // THIS IS A STUB // TODO Project2 } // end difference Lone return statement per method please /** return null; // THIS IS A STUB * Creates a new set of objects that are in this set and are less than a given object. + } // end union * @param a Entry a given object * @return a new set of objects that are in this set and are less than a Obiect * Creates a new set that contains those objects that occur in both this * set and other set without affecting the original two sets. public ArcasetwitharcayT>getAlll pss Than TanEntry) { * @param other set the given set // TODO Project2 * @return a set that is the intersection of the two sets // one return statement per method please +/ Lutilize compare to method public AccarsetWithocay intersection ArcasetWithArrayotberset { return null; // THIS IS A STUB // TODO Project2 } // end getAllLess Than // one return statement per method please * Checks if all the elements of the given set are also included in the other set return null; // THIS IS A STUB }// end intersection * @param other set set to check ----------- Il L -------- -------------- public boolean issubsetaccarsetwithstarotberset { // TODO Project2 /Lone return statement per method please 11 utilize difference method return false;//THIS IS A STUB } * Move the first element to be the last in the set by rotating the elements public void nooreFirstToEnd) { // TODO Project2 1L do not call add or remove }