Question: public class StringBag { // the array to hold the data private String [] bag; // the number of elements being held (also the next
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 inserts a String into the StringBag. If there is space in the bag, then the new element should be put at the next unoccupied slot in the array (at the end) and the method should return true. If there is no space, dont add anything, but just return false. i. Write your test case for this method. @Test public void testAdd() { // Replace this test with your code } ii. Write your method. public boolean add(String item) { // 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
