Due Monday, October 16 at 11:59 PM
By the time you have completed this work, you should be able to:
Take.java
Download the Take.java
file, and open it in jGrasp (or a text editor of your choice).
This program takes a number of command-line arguments and parses the first one as an integer N
.
It will then “take” the first N
arguments, producing a new array, and will print out the contents of this new array.
Example output of this program with the command-line arguments 3 first second third fourth
is shown below:
{3, first, second}
In the example above, the first argument states to “take” the first 3
elements from the command-line arguments.
The value 3
is itself a command-line argument, so it is included.
If we request more elements to “take” than there are command-line arguments, then the program should take as many as possible.
A second example is shown below which illustrates this behavior for the command-line arguments 30 hi
.
{30, hi}
With the above example, even though 30
values were requested to be taken, there are only two values present in the command-line arguments.
As such, only those two arguments can be provided.
The comments in Take.java
provide further details.
TakeTest.java
as a Test File
Download the TakeTest.java
file, being sure to put it in the same folder/directory as your Take.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.
Drop.java
Download the Drop.java
file, and open it in jGrasp (or a text editor of your choice).
This program takes a number of command-line arguments and parses the first one as an integer N
.
It will then “drop” the first N
arguments, producing a new array, and will print out the contents of this new array.
Example output of this program with the command-line arguments 3 first second third fourth
is shown below:
{third, fourth}
In the example above, the first argument states to “drop” the first 3
elements from the command-line arguments.
The value 3
is itself a command-line argument, so it is included.
If we request to “drop” more elements than there are command-line arguments, then the program should drop as many as possible.
A second example is shown below which illustrates this behavior for the command-line arguments 30 hi
.
{}
With the above example, even though 30
values were requested to be dropped, there are only two values present in the command-line arguments.
As such, this returns an empty array ({}
), since all the elements end up being dropped.
The comments in Drop.java
provide further details.
DropTest.java
as a Test File, and Edit It
Download the DropTest.java
file, being sure to put it in the same folder/directory as your Drop.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.
Log into Canvas, and go to the COMP 110L class. Click “Assignments” on the left pane, then click “Lab 12”. From here, you can upload your answers and your code. Specifically, you must turn in the following three files:
Take.java
Drop.java
DropTest.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.