Question: This lab will provide additional practice working with Strings by having you to parse a string and extract all of the tokens in the string,

This lab will provide additional practice working with Strings by having you to parse a string and extract all of the tokens in the string, given a source string and (optionally) a list of delimeters. 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). One other change I made to my ST class is to put a line or two of code in the constructor(s) so that it will print out the String that it is tokenizing, the list of delimeters, and the number of tokens. See my output below. Make your program do the same.
 
 D) If your program will allow you to pass in a list of delimeters (problem #4 below), it will be worth a maximum grade of 100. 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. Put your program in the file: ~/PF2/lab6/Lab6.java = TEST PROGRAM ======================================================== 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!