Question: A StringBag is a container that holds String objects. Consider the following starter code for a StringBag class. public class StringBag { // the array
A StringBag is a container that holds String objects. Consider the following starter code for a StringBag class.
public class StringBag {
// the array to hold the data
private String [] bag;
// the number of elements being held (also the next index where a new
// String can be put).
private int count;
public StringBag(int length) {
bag = new String[length];
count = 0;
}
}
[2 points] Write a function that returns the number of items that have been added to the StringBag object.
Write your test case for this method.
public void testSize()
// Replace this test with your code
Write your method.
public int size()
{
// Replace this test with your code
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
