Question: Question 1: (3 POINTS: 0.4 POINTS for each method and 0.6 for the Test program) Considering the following Stack interface: public interface Stack { boolean

Question 1: (3 POINTS: 0.4 POINTS for each method and 0.6 for the Test program) Considering the following Stack interface: public interface Stack  { boolean isEmpty (); E peek (); E pop (); void push (E item); void clear (E item); } We want to define the ArrayStack class which implements the Stack interface. ArrayStack uses a fixed-size array to store its elements and a top attribute which designates the first free cell of its table. ArrayStack therefore has a one-parameter constructor. Since the ArrayStack class realizes the Stack interface, it must provide a implementation for all interface methods. So you have to define these methods as well as the constructor: ArrayStack (int size): constructor isEmpty: returns true if the stack (ArrayStack) is empty E peek (): Return the top element of the stack without removing it E pop (): Remove and return the top element of this stack void push (E item): Place the item on top of this stack void clear (E item): remove all items from this stack. The battery will be empty following this call. Write a Test program to test your stack: - Create an object from your ArrayStack stack of the current type String. - Stack your stack of 10 items. - Completely empty your battery - Stack your stack of 10 items again. - Unstack your battery while displaying the removed item. / Example output * / Second time: 18 Second time: 16 Second time: 14 Second time: 12 Second time: 10 Second time: 8 Second time: 6 Second time: 4 Second time: 2 Second time: 0

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!