CJCoding With Joseph
15free / daySign inCreate account

Stackable Interface with Undo History

Create a class UndoHistory that implements the provided Stackable interface to track text actions.

Requirements:
- Use a String[] actions array of size 10 and an int top counter (starts at 0) to track the stack.
- push(String item) adds the item at index top and increments top. Ignore if full.
- pop() decrements top and returns the item. Return "empty" if nothing to pop.
- peek() returns the item at top - 1 without removing it. Return "empty" if stack is empty.

Do NOT write a main method.

Expected Output:

Typed B
Typed B
Typed A
empty

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
InterfacesClasses
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.