String.split
Due Wednesday, October 25 at 11:59 PM
By the time you have completed this work, you should be able to:
String.split
SubsetCopyArray.java
SubsetCopyArrayTest.java
Join.java
JoinTest.java
DiceRoller.java
DiceRollerTest.java
collaborators.txt
SubsetCopyArray.java
Download the SubsetCopyArray.java
file, and open it in jGrasp (or a text editor of your choice).
This program takes a number of command-line arguments, where the first two are:
All the command-line arguments are then collectively treated as a single array.
The given starting an ending indecies are used to make a copy of the array, starting from the given start and ending at the given end.
This array copy is finally printed out.
Example output of this program with the command-line arguments 2 5 hello goodbye first second third
is shown below:
{hello, goodbye, first, second}
The output above starts with hello
because hello
is at index 2
, and the user requested to start the copy at index 2
.
Similarly, the output above ends with second
because second
is at index 5
, and the user requested to stop the copy at index 5
.
SubsetCopyArrayTest.java
as a Test File, and Edit It
Download the SubsetCopyArrayTest.java
file, being sure to put it in the same folder/directory as your SubsetCopyArray.java
file.
This file contains tests for the methods you wrote in the previous step.
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.
Join.java
Download the Join.java
file, and open it in jGrasp (or a text editor of your choice).
This program takes a number of command-line arguments, and will combine them using a given String
(“,
” in the given code in main
).
Example output of this program with the command-line arguments first second third
is shown below:
first, second, third
There are two special cases:
Join.java
contains further information in the comments.
JoinTest.java
as a Test File, and Edit It
Download the JoinTest.java
file, being sure to put it in the same folder/directory as your Join.java
file.
This file contains tests for the methods you wrote in the previous step.
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.
DiceRoller.java
Download the DiceRoller.java
file, and open it in jGrasp (or a text editor of your choice).
This program takes a seed with which to create a random number generator from (using java.util.Random
).
This program will then roll a user-specified number of die, where the number of sides of each die is also user-specified.
For example, consider the following command-line arguments:
54321 3d20
The above arguments state the following:
54321
3
die should be rolled20
sides
Note that the 3d20
portion is a single argument.
You'll need to break this down into the 3
and 20
components.
You can use String.split
for this purpose.
Example output with the above command-line arguments is shown below:
Values: {9, 12, 3} Sum: 24
It is strongly recommended, though not required, to divide your solution across multiple methods, where each method handles one piece.
Internally, my own solution uses four methods, not including main
.
For example, you could define methods to:
N
-sided die onceN
-sided dice, which calls the aforementioned method3
and 20
as int
s, as opposed to “3d20
” as a String
.)DiceRollerTest.java
as a Test File
Download the DiceRollerTest.java
file, being sure to put it in the same folder/directory as your DiceRoller.java
file.
This file contains tests for the method you wrote in the previous step.
Open this file in jGrasp as a test file, using the same instructions you've used in previous labs.
You do not need to submit these tests, and you are not required to write any of your own tests for this portion.
However, for full credit, all the tests must pass.
Log into Canvas, and go to the COMP 110L class. Click “Assignments” on the left pane, then click “Lab 13”. From here, you can upload your answers and your code. Specifically, you must turn in the following five files:
SubsetCopyArray.java
SubsetCopyArrayTest.java
Join.java
JoinTest.java
DiceRoller.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 five files.
You can turn in the assignment multiple times, but only the last version you submitted will be graded.