Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Stack;
- import java.util.StringTokenizer;
- /**
- @author narishareddy
- */
- /**ReverseTokenizer class:
- This class uses a stack to store the token strings in reverse order and
- allows their retrieval. You must use what is below, but make sure to
- comment it properly. You cannot add any more methods or data, just finish
- the methods below and comment properly. Remove my comments.
- I am not requiring a testbed main for this class.
- */
- public class ReverseTokenizer
- {
- private Stack stack;
- public ReverseTokenizer ( String inString, String delimeters )
- {
- StringTokenizer st = new StringTokenizer(inString, delimeters);
- stack = new Stack(st.countTokens()); // Error.. see the end for error message
- // Create a StringTokenizer object
- // Initialize the stack (use StringTokenizer's countTokens method)
- // Take all tokens and push on the stack
- }
- public boolean hasMoreTokens()
- {
- return !stack.isEmpty();
- }
- public String nextToken()
- {
- return (String)stack.pop();
- // one-liner using a stack method
- }
- }
- ********************************************************
- Error Message for that line
- constructor Stack in class Stack<E> cannot be applied to given types;
- required: no arguments
- found: int
- reason: actual and formal argument lists differ in length
- where E is a type-variable:
- E extends Object declared in class Stack
- *******************************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement