Question: 1. (4 pts) A Bag object's public class Bag instance variable tracks how { many items are in a bag. private int numitems; Complete the

 1. (4 pts) A Bag object's public class Bag instance variable

1. (4 pts) A Bag object's public class Bag instance variable tracks how { many items are in a bag. private int numitems; Complete the add method so that all the items in the parameter have been transferred to the Bag that is calling the method. For example: public Bag(int n) { numitems = n; } public void add( Bag b) { Bag b1 = new Bag( 5 ); Bag b2 = new Bag( 7 ); b2.add( b1); int n1 = b1.get(); // n1 = 0 int n2 = b2.get(); // n2 = 12 } public int get() { return numitems; }

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!