Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.53 KB | None | 0 0
  1. import java.util.Stack;
  2. import java.util.StringTokenizer;
  3.  
  4. /**
  5.  
  6.  @author narishareddy
  7.  */
  8. /**ReverseTokenizer class:
  9.  
  10. This class uses a stack to store the token strings in reverse order and
  11. allows their retrieval. You must use what is below, but make sure to
  12. comment it properly. You cannot add any more methods or data, just finish
  13. the methods below and comment properly.  Remove my comments.
  14. I am not requiring a testbed main for this class.
  15. */
  16. public class ReverseTokenizer
  17. {
  18.    private Stack stack;
  19.  
  20.    public ReverseTokenizer ( String inString, String delimeters )
  21.    {
  22.        
  23.        StringTokenizer st = new StringTokenizer(inString, delimeters);
  24.        stack = new Stack(st.countTokens()); // Error.. see the end for error message
  25.      
  26.       // Create a StringTokenizer object
  27.       // Initialize the stack (use StringTokenizer's countTokens method)
  28.       // Take all tokens and push on the stack
  29.  
  30.  
  31.    }
  32.  
  33.    public boolean hasMoreTokens()
  34.    {  
  35.        return !stack.isEmpty();
  36.    }
  37.  
  38.    public String nextToken()
  39.    {  
  40.       return (String)stack.pop();
  41.       // one-liner using a stack method
  42.  
  43.    }
  44.  
  45. }
  46.  
  47. ********************************************************
  48. Error Message for that line
  49.  
  50. constructor Stack in class Stack<E> cannot be applied to given types;
  51.   required: no arguments
  52.   found: int
  53.   reason: actual and formal argument lists differ in length
  54.   where E is a type-variable:
  55.     E extends Object declared in class Stack
  56.  
  57. *******************************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement