char
, length()
, charAt()
, and an Introduction to Multidimensional ArraysDue Monday, October 30 at 11:59 PM
By the time you have completed this work, you should be able to write programs which:
char
typelength()
and charAt()
methods of String
StringExplode.java
Download the StringExplode.java
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:
{'f', 'o', 'o'}
StringExplodeTest.java
as a Test File, and Edit It
Download the StringExplodeTest.java
file, being sure to put it in the same folder/directory as your StringExplode.java
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.
MultiSplit.java
Download the MultiSplit.java
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 String
s (String[]
) along with a regular expression, and will call split()
on each one of those String
s 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 String
s.
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 0
th 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.
Log into Canvas, and go to the COMP 110L class. Click “Assignments” on the left pane, then click “Lab 14”. From here, you can upload your answers and your code. Specifically, you must turn in the following three files:
StringExplode.java
StringExplodeTest.java
MultiSplit.java
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.