Your cart is currently empty!
Problem 1 (30 points): Bag Client: Write a client class ConsonantsFilter that filters out all consonants from a bag containing letters. To accomplish this: Create three bags that hold strings. One bag is named letters and contains several one-letter strings. Another bag is named vowels and contain five strings, one for each vowel. The…
public void removeDuplicates() {…}
Write also a client class TestArrayBag to test the removeDublicates() method.
Hints for possible solutions of Problem 2:
Variant 1:
In order to remove the duplicates from the bag you can use a pair of nested loops. Both loops scan the bag array (an instance variable in the ArrayBag class):
Variant 2:
Use a second array (e.g. bag2), where you copy only the elements from the bag array that do not appear already there.
Here is a scheleton of the method:
public void removeAllDuplicates() {
@SuppressWarnings(“unchecked”)
T[] bag2 = (T[]) new Object[numberOfEntries];
int sizeBag2 = 0;
// unchecked cast
// number of elements in bag2
…..
…..
}
What to turn in: The classes ConsonantsFilter.java, ArrayBag.java, and TestArrayBag.java.
Important Note: Differently from the labs, the assignments are strictly individual. You are not allowed to use somebody’s code, or to present code found on the Web. The assignments which do not comply with these constraints will get zero points (both sides).