Question: 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; i index); 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

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!