Lab 10: Command-line Arguments, Integer.parseInt, and Arrays


Due Friday, October 6 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 Concatenate2.java

Download the Concatenate2.java file, and open it in jGrasp (or a text editor of your choice). This program takes two command-line arguments and will concatenate them together. If you're unsure how to pass command-line arguments to a program with jGrasp, see this tutorial. Example output of this program with the command-line arguments first second is shown below:

firstsecond

Step 2: Edit MinMaxCommandLineArgs.java

Download the MinMaxCommandLineArgs.java file, and open it in jGrasp (or a text editor of your choice). This program takes two values as command-line arguments, converts them to ints via Integer.parseInt, and determines the minimal and maximal value. To this end, you will need to copy your min and max methods from lab 6's MinMax.java file into MinMaxCommandLineArgs.java. Example output of this program is shown below, with the command-line arguments 3 7:

Min: 3
Max: 7

Further example output for the command-line arguments 28 10 is shown below:

Min: 10
Max: 28

Step 3: Edit Sum3.java

Download the Sum3.java file, and open it in jGrasp (or a text editor of your choice). This program will read in three integers with Scanner, put the values in an array of int, and then print the sum of the three values. Example output of the program is shown below, with user input shown in bold:

Enter first integer: 3
Enter second integer: 2
Enter third integer: 1
Sum: 6

More details about the method you need to write are in the comments of Sum3.java. Note that the method you need to write must handle input arrays holding fewer than three elements! The next step will check that additional behavior.

Step 4: Open Sum3Test.java as a Test File, and Edit It

Download the Sum3Test.java file, being sure to put it in the same folder/directory as your Sum3.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: 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 10”. From here, you can upload your answers and your code. Specifically, you must turn in the following four 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 four files.

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