Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Add a new method to BagInterface labbeld, toArrayList () that should return a

ID: 3849613 • Letter: 1

Question

1.   Add a new method to BagInterface labbeld, toArrayList() that should return all objects contained in the bag as an arrayList.

2.   In class ResizableArrayBag implement method toArrayList

3.   Create a new class Book that has the following properties/data and behaviors/methods

Properties:

author, title, numberOfPages

Methods:   

-   default constructor: sets all data members to their default values

-   constructor with 3 parameters, that initializes the data members accordingly.

-   Getter methods for all 3 data members

-   toString: returns a string containing all data members each prefixed with a description of the data member.

4.   Create a new class BookStore to test all methods of Book, and some of the BagInterface and ResizableArrayBag, more specifically from BagInterface methods add, remove, toArray & toArrayList and from ResizableArrayBag, all prior methods in addition to the default constructor.

a.   Test1, tests the Book methods

i.   methodA(), Create a book using default constructor then print object using toString. [check printed results correct or not]

ii.   methodB(), Create book using constructor with 3 parameters, then print object to screen using toString method. [check printed results correct or not]

iii.   methodC(), Create book using constructor with 3 parameters, then print object to screen using the getter methods. [check printed results correct or not]

b.   Test2, test Book, BagInterface and ResizableArrayBag methods .

i.   methodD(), Create a bag then add several books in it, then print all objects of the bag by looping and calling remove() in BagInterface [check printed results correct or not]

ii.   methodE(),Create a bag then add several books in it, then print all objects of the bag by calling toArray() method and printing the contents of the returned array. [check printed results correct or not]

iii.      methodF(),Create a bag then add several books in it, then print all objects of bag by calling toArrayList() method and printing the contents of the returned arrayList. [check printed results correct or not]

5.   Upload your homework to moodle as a zip file containing the source code files for BagInterface, ResizableArrayBag , Book and BookStore.

Explanation / Answer

Hi,

Since some of the information is missing from the questions, I have taken certain assumptions and stated them in the code wherever required. Comment to clarify the question so that I can update my answer accordingly, if the assumptions are wrong.

Assumptions are:

BagInterface:

ResizableArrayBag:

Book:

BookStore:

Hope it Helps!