Question: Write an extended class that has all the operations of the Bag class from Figure 5.2. Use Javas Vector as the superclass. FIGURE 5.2 Specification
Write an extended class that has all the operations of the Bag class from Figure 5.2. Use Java’s Vector as the superclass.









FIGURE 5.2 Specification and Implementation for the ArrayBag Generic Class ArrayBag * public class ArrayBag from the package edu.colorado.collections An ArrayBag is a collection of references to E objects. Limitations: (1) The capacity ofone of these bags can change after it's created, but the maximum capacity is limited by the amount of free memory on the machine. The constructors, add, clone, and union will result in an OutOfMemoryError when free memory is exhausted. (2) A bag's capacity cannot exceed the largest integer, 2,147,483,647 (Integer.MAX_VALUE). Any attempt to create a larger capacity results in failure due to an arithmetic overflow. (3) Because of the slow linear algorithms of this class, large bags will have poor performance. Specification Constructor for the ArrayBag public ArrayBag( ) Initialize an empty bag with an initial capacity of 10. Note that the add method works efficiently (without needing more memory) until this capacity is reached. Postcondition: This bag is empty and has an initial capacity of 10. Throws: OutofMemoryError Indicates insufficient memory for new Object[10].
Step by Step Solution
3.41 Rating (154 Votes )
There are 3 Steps involved in it
Heres an implementation of the Bag class using Javas Vec... View full answer
Get step-by-step solutions from verified subject matter experts
