Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in java code. no breaks in for loops pls ....................................................... public class ArraySetWithArray

in java code. no breaks in for loops pls

.......................................................

\public class ArraySetWithArray> implements SetInterface

{

// TODO Project2 #1

// open ResizableArrayBag in the split editor window

// the implementation of ArraySetWithArray methods will be similar

private T[] setOfEntries;

private int numberOfEntries;

private boolean initialized;

private static final int DEFAULT_CAPACITY = 3; // Initial capacity of array

private static final int MAX_CAPACITY = 10000;

/**

* Creates an empty array whose initial capacity is DEFAULT_CAPACITY.

*/

public ArraySetWithArray()

{

//TODO Project2 #2

} // end default constructor

/**

* Creates an empty array having a given initial capacity.

*

* @param capacity The integer capacity desired.

*/

public ArraySetWithArray(int capacity)

{

//TODO Project2 #3

} // end constructor

/**

* Creates an array containing given entries.

*

* @param contents An array of objects.

*/

public ArraySetWithArray(T[] contents, int numberOfEntries)

{

//TODO Project2 #6

// calls this.add not to allow null or duplicated elements

} // end constructor

/**

* Throws an exception if the client requests a capacity that is too large.

*/

private void checkCapacity(int capacity)

{

if (capacity > MAX_CAPACITY)

throw new IllegalStateException("Attempt to create a set whose capacity exceeds " +

"allowed maximum of " + MAX_CAPACITY);

} // end checkCapacity

/**

* Throws an exception if receiving object is not initialized.

*/

private void checkInitialization()

{

if (!this.initialized)

throw new SecurityException("Uninitialized object used " +

"to call an ArraySetWithArray method.");

} // end checkInitialization

/**

* Adds a new entry to this array, rejecting duplicates and null entries.

*

* @param newEntry The object to be added as a new entry.

* @return true if the addition is successful, or

* false in case of null entry or duplicate to be added.

*/

public boolean add(T newEntry)

{

//TODO Project2 #4

return false; //THIS IS A STUB

} // end add

/**

* Checks if the set is full; if it is full doubles its size

*/

private void ensureCapacity()

{

//TODO Project2 #4

} // end ensureCapacity

/**

* Retrieves all entries that are in this array.

*

* @return A newly allocated array of all the entries.

*/

public T[] toArray()

{

//TODO Project2

return null; //THIS IS A STUB

} // end toArray

/**

* Sees whether this array is empty.

*

* @return True if this array is empty, or false if not.

*/

public boolean isEmpty()

{

//TODO Project2

return false; //THIS IS A STUB

} // end isEmpty

/**

* Gets the number of entries currently in this array.

*

* @return The integer number of entries currently in the array.

*/

public int getCurrentSize()

{

//TODO Project2

return 0; //THIS IS A STUB

} // end getCurrentSize

/**

* Tests whether this array contains a given entry.

*

* @param anEntry The entry to locate.

* @return True if the array contains anEntry, or false if not.

*/

public boolean contains(T anEntry)

{

//TODO Project2

// utilize getIndexOf method

return false; //THIS IS A STUB

} // end contains

/**

* Locates a given entry within the array set.

* Returns the index of the entry, if located,

* or -1 otherwise.

* Precondition: checkInitialization has been called.

*/

private int getIndexOf(T anEntry)

{

int index = -1;

// TODO Project2

return index;

} // end getIndexOf

/**

* Removes all entries from this array.

*/

public void clear()

{

//TODO Project2

} // end clear

/**

* Removes one unspecified entry from this set.

*

* @return Either the removed entry if the removal

* was successful, or null if not.

*/

public T remove()

{

//TODO Project2

return null; //THIS IS A STUB

} // end remove

/**

* Removes one occurrence of a given entry from this array.

*

* @param anEntry The entry to be removed.

* @return true if the removal was successful, or false if not.

*/

public boolean removeElement(T anEntry)

{

//TODO Project2

return false; //THIS IS A STUB

} // end removeElement

/**

* Removes and returns the array entry at a given index.

*

* @param givenIndex index of the element to be removed

* @return remove an element or null if no such entry exists

*/

private T removeEntry(int givenIndex)

{

//TODO Project2

return null; //THIS IS A STUB

} // end removeEntry

//

// +++++++++++++++++++ NEW METHODS +++++++++++++++++++++++++++

//

/**

* Displays all entries in the set.

* 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

*/

public void displaySet()

{

//TODO Project2 #5

// do not call toArray since you have direct access to this.setOfEntries array

} // end displaySet

/**

* 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

}

/**

* Removes the largest entry from the this.setOfEntries

*

* @return - null if the set is empty

* or the largest element

*/

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

The Database Experts Guide To SQL

Authors: Frank Lusardi

1st Edition

0070390029, 978-0070390027

More Books

Students also viewed these Databases questions

Question

5. A review of the key behaviors is included.

Answered: 1 week ago

Question

3. An overview of the key behaviors is presented.

Answered: 1 week ago