Question: interface StackInterfaceHw 2 . java: / * * return without removing the oldest element that was added to the stack; if stack is empty then
interface StackInterfaceHwjava:
return without removing the oldest element that was added to the stack; if stack is empty then return null.
Example, If we had pushA; pushC; pushR; pushW; the top of stack would be W then if we call peekOldest it would return A and stack remains as is unchanged, ACRW & W is still top of stack.
@return the oldest data entered into the stack, without deleting the data from the stack
public T peekOldest;
swap the most recent element in the stack top of stack with the oldest element added to the stack and return True. If stack is empty return false.
Example, if the stack has ABCD and top of stack is D then after calling swap the stack would have DBCA with A being the top of stack
@return false: stack is empty
true: exchanged top of stack with bottom of stack so top of stack has
become bottom of stack and bottom of stack has become top of stack
public boolean swap;
This method searches stack for the given object t; if found, true is returned else false is returned.
@param t the object to search for
@return true if t is in the stack otherwise return false
public boolean searchT t;
public interface StackInterfaceHW
return without removing the oldest element that was added to the stack; if stack is empty then return null.
Example, If we had pushA; pushC; pushR; pushW; the top of stack would be W then if we call peekOldest it would return A and stack remains as is unchanged, ACRW & W is still top of stack.
@return the oldest data entered into the stack, without deleting the data from the stack
public T peekOldest;
swap the most recent element in the stack top of stack with the oldest element added to the stack and return True. If stack is empty return false.
Example, if the stack has ABCD and top of stack is D then after calling swap the stack would have DBCA with A being the top of stack
@return false: stack is empty
true: exchanged top of stack with bottom of stack so top of stack has
become bottom of stack and bottom of stack has become top of stack
public boolean swap;
This method searches stack for the given object t; if found, true is returned else false is returned.
@param t the object to search for
@return true if t is in the stack otherwise return false
public boolean searchT t;
Adds a new entry to the top of this stack.
@param newEntry An object to be added to the stack.
public void pushT newEntry;
Removes and returns this stack's top entry.
@return The object at the top of the stack.
@throws EmptyStackException if the stack is empty before the operation.
public T pop;
Retrieves this stack's top entry.
@return The object at the top of the stack.
@throws EmptyStackException if the stack is empty.
public T peek;
Detects whether this stack is empty.
@return True if the stack is empty.
public boolean isEmpty;
Removes all entries from this stack.
public void clear;
end StackInterface
A LinkedStackHW
What I want you to do for this homework is to modify class LinkedStack and rename it to be LinkedStackHWjava and have it implement the new interface StackInterfaceHw
So LinkedStackHW will have everything LinkedStack had before and in addition it will implement the new methods in the interface,
public T peekOldest;
public boolean swap;
public boolean searchT t;
B Main method in LinkedStackHW
To test that your methods in class LinkedStackHW are implemented correctly, I want you to write several test cases, to test each of the methods; at a minimum, do the following tests and print out their results to the screen.
B test peekOldest with stack having data
B test peekOldest with stack empty
B test for swap
B test for search with searchItem in the stack
B test for search with searchItem not in the stack
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
