Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Load to the IDEA the remaining classes from the provided Lab02.zip file. Repeat the previous project inside the ArraySetWithArray class. As shown in the UML

Load to the IDEA the remaining classes from the provided Lab02.zip file. Repeat the previous project inside the ArraySetWithArray class. As shown in the UML diagram below ArraySetWithArray class does not utilize ResizableArrayBag object as its instance variable, it has setOfEntries defined as an array which should be dynamically resized if more room needed (double the size). displaySet method should check if the set is empty and display appropriate message; if the set is not empty should display the number of elements and the capacity, followed by all the elements in the set (see sample run). Test your class with the test cases provided in main. See the sample run below. 
public class ArraySetWithArray> implements SetInterface { private T[] setOfEntries; private int numberOfEntries; private boolean initialized = false; 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 3. */ public ArraySetWithArray() { //TODO Project2 } // end default constructor /** * Creates an empty array having a given initial capacity. * * @param capacity The integer capacity desired. */ public ArraySetWithArray(int capacity) { //TODO Project2 } // end constructor /** * Creates an array containing given entries. * * @param contents An array of objects. */ public ArraySetWithArray(T[] contents) { //TODO Project2 } // 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 bag 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 ArrayBag method."); } // end checkInitialization /** * Adds a new entry to this array, avoiding duplicates. * * @param newEntry The object to be added as a new entry. * @return True if the addition is successful, or false if not. */ public boolean add(T newEntry) { //TODO Project2 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 } // 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; } // 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 bag. * Returns the index of the entry, if located, * or -1 otherwise. * Precondition: checkInitialization has been called. */ private int getIndexOf(T anEntry) { int where = -1; // TODO Project 2 return where; } // end getIndexOf /** * Removes all entries from this array. */ public void clear() { //TODO Project2 } // end clear /** * Removes one unspecified entry from this bag. * * @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 null if not. */ public boolean removeElement(T anEntry) { //TODO Project2 return false; } // end removeElement // Removes and returns the array entry at a given index. // If no such entry exists, returns null. private T removeEntry(int givenIndex) { //TODO Project2 return null; //THIS IS A STUB } // end removeEntry // Displays a 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 } // end displaySet

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 Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

6th International Edition

061921323X, 978-0619213237

More Books

Students also viewed these Databases questions

Question

Types of Interpersonal Relationships?

Answered: 1 week ago

Question

Self-Disclosure and Interpersonal Relationships?

Answered: 1 week ago