Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

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

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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions