Question: A StringBag Abstract Data Type (ADT) is a simple collection of strings ordered by time of entry (not alphabetical) . Like a stack, the last

A StringBag Abstract Data Type (ADT) is a simple collection of strings ordered by time of entry (not alphabetical) . Like a stack, the last string entered goes on the top. The strings are not alphabetized in the bag.

Client programs can insert string s into the bag , check its size, clear it, use its toString , remove the top string, and check to see i f it is full. W e want to k eep things simple, so we allow duplicates. There is no provision to see if a given string is already in the b ag. Further, the client can only remove the st r ing on top , like a stack . The StringBag is a LIFO collection. See the StringBagInterface , below.

Create a class to implement the interface using a private linked lis t to hold the inserted strings.

Note: if the list is not empty, then the following code wi ll remove the first item in a linked list: head = head.getLink( ) ; Design a test driver that show s that your St ringBag.java class works correctly.

public interface StringBagInterf ace {

void insert(String element);

// Precondition : This StringBag is not full.

// Places element into this StringLog.

boolean isFull();

// Returns true if this StringBag is full, otherwise returns false.

boolean isEmpty();

// Re turns true if this StringBag contains no strings.

int size();

// Returns the number of Strings in this StringBag.

String remove();

// Precondition: the Bag is not empty

// Removes the string at the top of t he bag and returns it.

void clear();

// Makes this StringBag empty.

String getName();

// Returns the name of this StringBag

String toString();

// Returns a nicely for matted string representing the

// name of the bag and all of its contents.

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!