Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started