Lab 16: Working with Multiple Files and an Introduction to Objects


Due Monday, November 6 at 11:59 PM

Goals for This Lab

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

Provided files:

Step-by-Step Instructions

Step 1: Edit PrintString.java

Download the PrintString.java file, and open it in jGrasp (or a text editor of your choice). You will need to define a static method that prints out a given String. The comments in the file provide more details.

Step 2: Edit PrintInt.java

Download the PrintInt.java file, and open it in jGrasp (or a text editor of your choice). You will need to define a static method that prints out a given int. The comments in the file provide more details.

Step 3: Edit PrintMain.java

Download the PrintMain.java file, and open it in jGrasp (or a text editor of your choice). You will need to write code in main that calls the methods you defined in PrintString.java and PrintInt.java. Specifically, the code you write needs to print out the first command-line argument as a String, and the second command-line argument as an int. Example output of this program with the command-line arguments foo 42 is shown below:

foo
42  

Step 4: Edit TwoInts.java

Download the TwoInts.java file, and open it in jGrasp (or a text editor of your choice). This file requires you to write a class containing two instance variables, a constructor, and an instance (non-static) method. This file already contains a main method, which can be used to test your code. main takes two command-line arguments, which it treats as int with which to call your TwoInts constructor. It will then call your printMe method on the created object. Once your code is correctly written, this program with the command-line arguments 4 5 should output the following:

First: 4
Second: 5

Step 5: Edit TwoOperations.java

Download the TwoOperations.java file, and open it in jGrasp (or a text editor of your choice). You will have to define two static methods which will use your TwoInts class you defined in the previous step, as well as defining a main method which will call the aforementioned methods. The comments in TwoOperations.java provide further details. Example output for this program with the command-line arguments 4 5 is shown below:

First: 0
Second: 4
First: 9
Second: -1

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