X364: ArrayBasedStack toString

Write the toString() member method for an ArrayBasedStack. When invoked the method must return the String representation of each entry that appears in the Stack concatenated together in the following form, the toString() method should return "[]", if the stack is empty, and "[bottom, item, ..., item, top]", if the stack contains items.

Your ArrayBasedStack<T> toString() member method implementation will be inserted/compiled inside the ArrayBasedStack<T> class code as covered in course module/lecture. The member fields your method implementations may access/change are:



public static final class ArrayBasedStack<T> implements StackInterface<T>
{
    private T[] contents;
    private int numberOfEntries;
    private int capacity;
    ...
}

Examples:

Test toString() on a 1 element stack.

Your Answer:

Reset

Practice a different Java exercise

Feedback

Your feedback will appear here when you check your answer.