Lab 16: length(), split(), and an Introduction to Multidimensional Arrays

Due Thursday, December 1 at 11:59 PM

Goals for This Lab

By the time you have completed this work, you should be able to write programs which:

Provided files:

Step-by-Step Instructions

Step 1: Edit

Download the file, and open it in jGrasp (or a text editor of your choice). This program will “explode” a String into an array of characters (char[]), and then print out the array. The String comes from the first command-line argument. Example output with the command-line argument foo is below:


Step 2: Open as a Test File, and Edit It

Download the file, being sure to put it in the same folder/directory as your file. Open this file in jGrasp as a test file, using the same instructions you've used in previous labs. You need to write a number of tests in this file, and all of them must pass. The comments in the file provide more details.

Step 3: Edit

Download the file, and open it in jGrasp (or a text editor of your choice). You will need to write a method that will take an array of Strings (String[]) along with a regular expression, and will call split() on each one of those Strings with the given regular expression. The result of this method should be a two-dimensional array of String (String[][]).

You will also need to write a method to print out this two-dimensional array of Strings.

The main method will call both methods, using “,” as the regular expression. Example output is shown below, which corresponds to the command-line arguments "one,two,three" "alpha,beta,gamma" "delta" "first,second":

0: one two three 
1: alpha beta gamma 
2: delta 
3: first second 

The output above shows that the 0th element ("one,two,three") produced the values one, two, and three when a split with “,” was performed. Each subsequent line follows the same general pattern for all the subsequent indicies in the command-line arguments array.

Step 4: Turn in Your Solution Using Canvas

Log into Canvas, and go to the COMP 110 class. Click “Assignments” on the left pane, then click “Lab 16”. From here, you can upload your answers and your code. Specifically, you must turn in the following three files:

In addition, if you collaborated with anyone else, be sure to download collaborators.txt and write the names of the people you collaborated with in the file, one per line. Please submit this file along with the other three files.

You can turn in the assignment multiple times, but only the last version you submitted will be graded.