Question: 28. Add the following methods to the ArrayBoundedStack class, and create a test driver for each to show that they work correctly. In order to

28. Add the following methods to the ArrayBoundedStack class, and create a test driver for each to show that they work correctly. In order to practice your array related coding skills, code each of these methods by accessing the internal variables of the ArrayBoundedStack, not by calling the previously defined public methods of the class.

A. String toString()creates and returns a string that correctly represents the current stack. Such a method could prove useful for testing and debugging the class and for testing and debugging applications that use the class. Assume each stacked element already provided its own reasonable toString method.

B. int size()returns a count of how many items are currently on the stack. Do not add any instance variables to the ArrayBoundedStack class in order to implement this method.

C. void popSome(int count)removes the top count elements from the stack; throws StackUnderflowException if there are less than count elements on the stack.

D. boolean swapStart()if there are less than two elements on the stack returns false; otherwise it reverses the order of the top two elements on the stack and returns true.

E. T poptop( )the classic pop operation, if the stack is empty it throws StackUnderflowException; otherwise it both removes and returns the top element of the stack.

the java flies

package ch02.stacks;

public class ArrayBoundedStack01 implements StackInterface { public ArrayBoundedStack01() { }

public void push(T element) // Throws StackOverflowException if this stack is full, // otherwise places element at the top of this stack. { }

public void pop() // Throws StackUnderflowException if this stack is empty, // otherwise removes top element from this stack. { }

public T top() // Throws StackUnderflowException if this stack is empty, // otherwise returns top element of this stack. { return null; }

public boolean isEmpty() // Returns true if this stack is empty, otherwise returns false. { return true; }

public boolean isFull() // Returns true if this stack is full, otherwise returns false. { return false; } }

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!