Question: StackBox Concept : Implement our own stack class patterned after Java's Stack class. See slides in class for details. Start with a generic class that

StackBox Concept :

Implement our own stack class patterned after Java's Stack class. See slides in class for details. Start with a generic class that uses an ArrayList for storage of the elements.

public class StackBox { ArrayList stack = new ArrayList(); }

(you may use an Array instead of the ArrayList if you like or you could use your ArrayBox instead of the ArrayList if you like. I think using Java's own ArrayList would be the easiest.) Part I:

Implement the following methods in StackBox:

boolean empty() Tests if this stack is empty. E push(E item) Pushes an item onto the top of this stack. Returns item pushed. E pop() Removes the object at the top of this stack and returns that object as the value of this function. E peek() Looks at the object at the top of this stack without removing it from the stack.

Refer to my slides in class for exact specifications details for each of these methods. Specifically, for full marks your StackBox must throw exceptions as described in their JavaDoc specification (again see class slides).

Part II: Palindrome

Using your StackBox class, create a driver program that can determine if an input string provided by a user is a palindrome (spells the same forward as backward). Again, see class slides for discussion of this algorithm. For full marks, your solution must use your StackBox and it must use methods push, pop, and empty. Sample output:

Enter a string> tenet

The word tenet is a palindrome.

Thanks for ur help!

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!