Question: In this assignment you are to implement ArrayBag as a generic class with a type parameter T for the elements in the bag. The template

 In this assignment you are to implement ArrayBag as a generic
class with a type parameter T for the elements in the bag.

In this assignment you are to implement ArrayBag as a generic class with a type parameter T for the elements in the bag. The template is the non-generic code given in the book (pp 137-141), see also the relevant slides. Exercises-Requirements 0. (5pts)Declare the generic ArrayBag class with the necessary interface clause 1. (5pts) Keep the two private data fields, each with the properly selected type for the array elements of index k follows 2. (5pts) Add a getter and setter for the array, as well as a getter and setter 3. Implement the methods and constructor with the added requirements as .(Opts) Eliminate the no-arg constructor (15pts) The constructor taking initialCapacity for parameter is modified as follows: the constructor takes a T type array for parameter -if the parameter is null, an IllegalArgumentException is thrown with a message of your choice otherwise the parameter is used to initialize the array field The constructor takes a second parameter of type int to initialize the manyltems field; if this parameter is the array length or greater, the field is initialized to the array length (5pts) add() : adjust the type for the parameter: it must be the class generic type or a subtype of that (must declare the subtype as a generic type for the method); no other change (10pts) addAll): adjust the type of the parameter the same way as for add(); the method checks if the parameter bag is null or the array field of the parameter is empty, in either case send a message "Nothing was added to the bag" to the console and return the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!