Lab 5: More Methods and an Introduction to Testing with JUnit


Tuesday, September 27 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 PerimeterCalculationMethod.java

Download the PerimeterCalculationMethod.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. Unlike with previous labs, you may not modify the code in the main method. More details are in the comments of PerimeterCalculationMethod.java. Example output of the program is shown below, with user input shown in bold:

Enter width: 2
Enter height: 3
Perimeter: 10

Step 2: Edit DegreeConversionMethod.java

Download the DegreeConversionMethod.java file, and open it in jGrasp (or a text editor of your choice). You will need to define a method in order to get this code compiling, and you may not modify the main method. DegreeConversionMethod.java contains more details in the comments. Example output of the program is shown below, with user input shown in bold:

Enter temperature in Celsius: 4.5
Fahrenheit: 40.1

Step 3: Edit CompoundInterestMethod.java

Download the CompoundInterestMethod.java file, and open it in jGrasp (or a text editor of your choice). You will need to define a method in order to get this code compiling, and you may not modify the main method. CompoundInterestMethod.java contains more details in the comments. Example output of the program is shown below, with user input shown in bold:

Enter principle (long): 53
Enter annual interest rate (double): 0.02
Enter number of times interest is compounded per year (int): 6
Enter number of years invested (int): 18
Compound interest including principal: 75.92099374307139

Step 4: Configure jGrasp to Use JUnit

If you're using jGrasp, you'll need to configure jGrasp to use JUnit. You can do this by following the instructions here. You only need to do this once per computer you have jGrasp installed on.

Step 5: Download, Open, Compile, and Run the Tests In PerimeterCalculationMethodTest.java

Download the PerimeterCalculationMethodTest.java file, being sure to put it in the same folder/directory as your PerimeterCalculationMethod.java file from step 1. PerimeterCalculationMethodTest.java contains a bunch of tests for the calculatePerimeter method you wrote in step 1. Use the instructions here to open PerimeterCalculationMethodTest.java as a tests file, then compile and run the tests. All the tests have been provided, and assuming you implemented your calculatePerimeter method correctly, they should all pass.

While you don't need to edit any code for this step, be sure to save PerimeterCalculationMethodTest.class in a safe spot. This file is produced automatically by jGrasp upon compiling and running the tests. This file will later be submitted along with the rest of the code you write.

Step 6: Copy Over MultiplySeven.java and MultiplyBoth.java From the Previous Lab

In the previous lab, you had to write code in MultiplySeven.java and MultiplyBoth.java. Copy over those two files into the same folder/directory where the rest of the files for this lab are. In this lab, you will write tests for the methods you wrote in the previous lab.

Step 7: Edit MultiplySevenTest.java

Download the MultiplySevenTest.java file, being sure to put it in the same folder/directory as your MultiplySeven.java file. MultiplySevenTest.java contains a bunch of tests for the multiplyBy7 method you wrote in the previous lab. One test has already been provided for you, namely zeroTimesSevenIsZero. You will need to write two more tests, which are described in the comments in the file.

Step 8: Edit MultiplyBothTest.java

Download the MultiplyBothTest.java file, being sure to put it in the same folder/directory as your MultiplyBoth.java file. MultiplyBothTest.java contains a bunch of tests for the multiplyBoth method you wrote in the previous lab. One test has already been provided for you, namely zeroTimesOneIsZero. You will need to write three more tests, which are described in the comments in the file.

Step 9: 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 5”. From here, you can upload your answers and your code. Specifically, you must turn in the following six 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 six files.

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