Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I am working on implementing my own version of a StringTokenizer class, this is what I've come up with so far. I've been working on
I am working on implementing my own version of a StringTokenizer class, this is what I've come up with so far. I've been working on it for a week, but stuck on what to do next. You are to implement your own version of the StringTokenizer class. Your program should function identically to the StringTokenizer class, but you are only required to implement the methods/constructors that are called from the test program (below). Your program should use the test program shown below, but should work for other sets of data as well. Do not modify my main method except for commenting out the sections of code which you have not (yet) implemented. NOTE: Your program can not use the StringTokenizer class or any other class or method that we have not covered in class. One simplifying assumption I made when I wrote my program is to assume that the Strings that are passed in will have no more than 50 tokens. Depending on how you write your program, this will make your code a tiny bit simpler. class ST { private String star[]; private int index = 0; private int numtokens =0; public ST(String s, String d) { star = new String[50]; String str = s; int start = 0; int end = 0; String delim = d; for(int i=1; iindex); public String nextToken() { return star[index++]; } } public class Lab6 { public static void main(String argv[]) { String str; //1) str = "Hello world"; ST stok= new ST(str); System.out.println("[" + str + "]"); while (stok.hasMoreTokens()) { System.out.println("#tokens = " + stok.countTokens()); System.out.println("token: [" + stok.nextToken() + "]"); } System.out.println("#tokens = " + stok.countTokens()); //System.out.println("token: " + stok.nextToken()); System.out.println(" "); //2) str = " Hello world "; stok= new ST(str); System.out.println("[" + str + "]"); while (stok.hasMoreTokens()) { System.out.println("#tokens = " + stok.countTokens()); System.out.println("token: [" + stok.nextToken() + "]"); } System.out.println("#tokens = " + stok.countTokens()); System.out.println(" "); //3) str = "root:x:0:0:root:/root:/bin/bash"; stok = new ST(str, ":"); System.out.println("[" + str + "]"); int n = stok.countTokens(); System.out.println("#tokens = " + n); for (int i=0; i
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started