Lab 10: Boolean Operations


Due Monday, October 24 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 InRange.java

Download the InRange.java file, and open it in jGrasp (or a text editor of your choice). This program will ask the user for three integers:

The program will then report whether or not the given arbitrary integer fit within the range. Example output of the program is shown below, with user input shown in bold:

Low end of range: 1
High end of range: 10
Number: 3
In range: true
Out of range: false

With the output above, because 3 is between 1 and 10, the number is in range (true) and the number is not out of range (false). Further example output of the program is shown below, with user input shown in bold:

Low end of range: 1
High end of range: 5
Number: 5
In range: true
Out of range: false

With the output above, 5 is considered in range because the range is inclusive. That is, the range from 1 to 5 includes 5.

For full credit, you must implement the outOfRange method as the Boolean negation of a call to the inRange method!

Step 2: Open InRangeTest.java as a Test File, and Edit It

Download the InRangeTest.java file, being sure to put it in the same folder/directory as your InRange.java file. This file contains a number of tests for the method 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 3: Edit ScoreDice.java

Download the ScoreDice.java file, and open it in jGrasp (or a text editor of your choice). This program will first ask the user for a seed value for Random. Using this seed, the program will simulate rolling two 6-sided die with the provided rollD6 method. Your task is to implement the scoreWithNumbers method, which will produce a score for the given dice rolls with the following rules:

  1. If one rolled two 1's or two 6's, the score is 10.
  2. If one rolled two of the same thing (but not double 1's or 6's), the score is 8.
  3. If one rolled two different values, the score is equal to whichever value is smaller.

Example output of the program is shown below, with user input shown in bold:

Enter seed: 321
Score: 5

For handling the third scoring rule above, you can either use your min definition from Lab 8, or you can use Java's Math.min method. You can also implement the logic for min directly in scoreWithNumbers, though this will require more work with no real added benefit.

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

Download the ScoreDiceTest.java file, being sure to put it in the same folder/directory as your ScoreDice.java file. This file contains a number of tests for the scoreWithNumbers method 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 110 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.