Question: in java Define a class ArraySetWithResizableArrayBag that represents a set and implements the SetInterface (described in Segment 1.21 of chapter 1). Use the class ResizableArrayBag
in java
Define a class ArraySetWithResizableArrayBag that represents a set and implements the SetInterface (described in Segment 1.21 of chapter 1). Use the class ResizableArrayBag in your implementation as defined in the UML diagram below: the instance variable setOfEntries is defined as ResizableArrayBag object. Test your class with the test cases provided in main. Load to IDEA only the classes needed for this project from the provided Lab02.zip file. Make sure that the DEFAULT_CAPACITY in ResizableArrayBag is set to 3.
Most of the methods can be implemented by simply calling appropriate methods from the ResizableArrayBag, for example the clear method would be implemented as:
THE TODO Sections
public void clear() { this.setOfEntries.clear(); } NOTE:
- Ensure that your add method does not allow duplicates and checks for null entries.
- The third constructor: public ArraySetWithResizableArrayBag(T[] contents) must call your add method to populate this.setOfEntries with elements from the passed contents array (check for null elements!).
public class ArraySetWithResizableArrayBag> implements SetInterface { private ResizableArrayBag setOfEntries; public ArraySetWithResizableArrayBag() { //TODO Project1 } // end default constructor public ArraySetWithResizableArrayBag(int capacity) { //TODO Project1 } // end of secondary constructor public ArraySetWithResizableArrayBag(T[] contents) { //TODO Project1 } public void clear() { this.setOfEntries.clear(); } // end clear public boolean add(T newEntry) { //TODO Project1 return false; //THIS IS A STUB } // end add public boolean removeElement(T anEntry) { //TODO Project1 return false; //THIS IS A STUB } // end remove public T remove() { //TODO Project1 return null; //THIS IS A STUB } // end remove public boolean contains(T anEntry) { //TODO Project1 return false; //THIS IS A STUB } // end contains public int getCurrentSize() { //TODO Project1 return 0; //THIS IS A STUB } // end getCurrentSize public boolean isEmpty() { //TODO Project1 return false; //THIS IS A STUB } // end getLength public T[] toArray() { //TODO Project1 return null; //THIS IS A STUB } // end toArray // Displays a set. // If the set is empty displays a message that the set is empty // if the set is not empty displays the number of elements and the content of the set public void displaySet() { //TODO Project1 } // end displaySet
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
