Integer.parseInt, and Arrays
Due Wednesday, November 2 at 11:59 PM
By the time you have completed this work, you should be able to:
charAt()to extract individual characters (i.e., values of type
char) out of
Integer.parseIntto convert values of type
Stringto values of type
FirstChar.java file, and open it in jGrasp (or a text editor of your choice).
This program takes a single command-line argument and prints out the first character of this argument, using
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 argument
foo is shown below:
First char: 'f'
Note that the output character is surrounded by single quotes (
'); you'll need to match this output exactly.
As a hint, you can do this with the help of string concatenation.
Sum2.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
Integer.parseInt, and adds them together.
Example output of this program is shown below, with the command-line arguments
Further example output for the command-line arguments
28 10 is shown below:
ProductUpTo3.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 product 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: 4 Enter third integer: 5 Product: 60
More details about the method you need to write are in the comments of
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.
ProductUpTo3Test.javaas a Test File, and Edit It
ProductUpTo3Test.java file, being sure to put it in the same folder/directory as your
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 110 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 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.