Lab 13: Even More Loops and Arrays, Along With String.split


Due Wednesday, October 25 at 11:59 PM

Goals for This Lab

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

Provided files:

Step-by-Step Instructions

Step 1: Edit 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:

  1. An integer representing a starting index in an array, inclusive
  2. An integer representing an ending index in an array, inclusive

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.

Step 2: Open 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.

Step 3: Edit 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:

  1. There are no arguments to combine (the input array is empty)
  2. There is only one argument to combine (the input array contains only one element)

Join.java contains further information in the comments.

Step 4: Open 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.

Step 5: Edit 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:

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:

Step 6: Open 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.

Step 7: Turn in Your Solution Using Canvas

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:

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.