Question: Consider a presentation of StringStack where we have a PR Person wrapper class, StringStack, and a StringStackltem class representing the inner structure of the stack.

 Consider a presentation of StringStack where we have a "PR Person"

wrapper class, StringStack, and a StringStackltem class representing the inner structure of

the stack. The StringStackltem class looks like the following: class StringStackItem String

Consider a presentation of StringStack where we have a "PR Person" wrapper class, StringStack, and a StringStackltem class representing the inner structure of the stack. The StringStackltem class looks like the following: class StringStackItem String data; I/ Top of the stack at this point StringStackItem rest; // Rest of the stack //Implementation of toString method found below And we have the following StringStack wrapper class: public class StringStack f private StringStackItem top; public StringStackO f // Create an empty stack top null; public void push(String s) StringStackItem item new StringStackItemO item.data -a item.rest top; top - item; // Select the correct implementation of toString method Let's say we want to write an implementation of toString which will create a String representing the data represented by the StringStack. The top item is on the left, second from the top to the right of that, all the way down to the bottom item on the right. The items are separated by commas and surrounded by square brackets. If we started with an empty stack and called toString, we should get "]" (left bracket followed by right bracket. If we pushed 1 followed by 2 followed by 3, then called toString on the stack, we should get "[1, 2, 3" We can write following toString implementation within StringStackltem which creates a string representing the internals of the StringStack public String toStringO if (restnull) return data return data + ", " + rest.toStringO; Which of the following implementations of toString will work for the StringStack wrapper class? It can make use of StringStackltem's toString The toString method should work correctly for empty and non-empty stacks. public String toStringO return "[" + top.toStringO "]"; public String toStringO if (top == null) return " "; return "C" + toStringO "]" public String tostringO if (top null) return "[]"; return "[" + top.tostring() + ""; public String toString) return "" + toStringO

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!