I have a school programming assignment involving stacks that I am completely stuck on for some reason, and I need a good kick in the right direction. I am going to post the complete assignment instructions so that I don't miss anything out, then I'll post my code and where I'm stuck at.
Instructions: For this assignment, you are to develop a SmartString class that supports insert into a
string, delete a substring from a string, and an undo method. Your SmartString class must conform to (implement) the following interface:
You must use a Stack to store the operations in order to support undo operations. Note that multiple undo operations can be performed in sequence. Using the
Java API Stack is fine or you can use ArrayStack from the textbook. Design a class to hold the required information to be placed onto the stack. Only the changes should be stored and not the whole string.
You should write a driver program to instantiate a SmartString and thoroughly
test your methods. A portion of your grade will be based on how well you test your SmartString class. You should handle stack underflow, but you can assume that the driver will not have any Index out of Bounds errors.
Here is my code, including the files she gave us to use the various methods. My file will be at the bottom (ArrayStack)
**Note: I have not done anything with the driver and the code is blank for it, so I didn't paste that as I was going to do that after I got the methods done.**
The Issue I'm having is with the Undo() method. As the instructions state, she only wants the changes stored. The way I have it currently is that it stores the "new" string after every change and then can use pop to revert the most recent change and have the string prior to the change as a result. The professor said that was incorrect, so I am stuck and have no idea where to start.