Lab 4: Introduction to Methods


Due Wednesday, September 13 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 HelloMethod.java

Download the HelloMethod.java file, and open it in jGrasp (or a text editor of your choice). Unlike with previous labs, you are not permitted to write your own System.out.print or System.out.println statements. Nonetheless, you must write a program which prints “Hello!” three times. That is, the output of your program should be as follows:

Hello!
Hello!
Hello!

In order to print this output without using your own System.out.print or System.out.println statements, you'll need to call the predefined printHello method three times. These calls will need to be in the main method. Note that you may not modify the printHello method.

Step 2: Edit AddFive.java

Download the AddFive.java file, and open it in jGrasp (or a text editor of your choice). You'll need to implement the body of the addFive method, without modifying the main method. More details are in the comments of AddFive.java. Example output of the program is shown below, with user input shown in bold:

Enter an integer: 4
With 5 added: 9

Step 3: Edit AddBoth.java

Download the AddBoth.java file, and open it in jGrasp (or a text editor of your choice). You'll need to implement the body of the addBoth method, without modifying the main method. More details are in the comments of AddBoth.java. Example output of the program is shown below, with user input shown in bold:

Enter an integer: 2
Enter a second integer: 3  
Result: 5

Step 4: Edit ConcatenateStringInt.java

Download the ConcatenateStringInt.java file, and open it in jGrasp (or a text editor of your choice). You'll need to implement the concatenate method, without modifying the main method. More details are in the comments of ConcatenateStringInt.java. Example output of the program is shown below, with user input shown in bold:

Enter string: bar
Enter integer: 81
Concatenated: bar81

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 4”. 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.