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;
}
}
Write a function that returns the number of strings that currently held in the StringBag (not the total capacity of the bag).
i.Write your test case for this method.
| public void testSize() { // Replace this test with your code }
|
ii.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
