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

1. The function add(int location, int item) is not a valid operation of bags. ad

ID: 3798507 • Letter: 1

Question

1. The function add(int location, int item)      

       is not a valid operation of bags.
       adds the item at the end of the bag.
       replaces the item in the bag at the position specified by location.
       adds the item to the bag at the position specified by location.

2. What list operation does the operation method below define?

               public void operation(int item)
               {
                              if (numberOfItems == SIZE) System.out.println("ERROR");
                              else
                              {
                                             listArray[numberOfItems] = item;
                                             numberOfItems++;
                              }
               }        clear
       remove
       add
       display

Explanation / Answer


public void operation(int item)
{
// if total number of items in listArray is equal to size, print error
if (numberOfItems == SIZE) System.out.println("ERROR");

// else put the item at the end of the listArray and increment count of
// the total number of itms in listArray
else
{
listArray[numberOfItems] = item;
numberOfItems++;
}
}

Given function does the add operation to the listArray