Logical Operators

Note:  Please keep the programs that you create today, in case you have a question about your grades for the ICEs at the end of the quarter. When you're working with a partner, each person should save his-or-her own copy.

## ICE 14.0: Logical Operators (Reference)

Please consult the demo files as reference when working on this exercise.

For this exercise we will be "testing" the static (non-moving) location of two robots, mary and fred in the LogicalOperators.java program.

The tests are constructed around mary and fred being at specific intersections in the city (PLEASE NOTE: mary and fred will not be moving):

mary is on Street 3 and Avenue 7
fred is on Street 14 and Avenue 4

Do not change the code to move them. To repeat, mary and fred will not move during the course of the program.

The only code you will be changing/adding down in main is some test code for the isSouthOfStreet5() method (for both mary and fred)

As you work down through the code, please read all the comments. They will aid you in figuring out what you are supposed to do, and instruct what operators are expected, whether the AND && operator, the OR || operator, or the NOT ! operator (or a combination of operators).

NOTE: there is some logic involved here to determined how the various methods are to coincide with the test code called down in main

When you get done reading this, go on to the next section.

## ICE 14.1: Warmup: Creating Predicate Methods

Download the LogicalOperators.java file linked above, and examine the code for the isNorthOfStreet10() method.

Make sure that the test code (in main) produces the correct results for your command.

Then go on to write in the missing code for isSouthOfStreet5() method, and add some test code to main to make sure it works.

Write the missing code for the isNorthOfStreet(int theStreet) method. This is similar to the isSouthOfStreet5() method but uses a variable parameter.

When you get done with this exercise, show your Instructor, then go on to the next section.

## ICE 14.2: Creating Predicate Methods: Logical Operators: Not (!)

Continue working with the file LogicalOperators.java, and write the predicate method called:

isInRangeOfStreets(int northMost, int southMost)

Now, write the predicate method called:

isNOTInRangeOfStreets(int northMost, int southMost.

This tests whether a robot is outside a given range of streets.

This method should work by calling the isInRangeOfStreets() you created above, and using the NOT operator! to reverse the answer it gets, and then to return that answer.

When you get done with this exercise, show your Instructor, then go on to the next section.

## ICE 14.3: Creating Predicate Methods: Logical Operators: Or (||)

Continue working with the file LogicalOperators.java, and write the predicate method called:

isOutsideRangeOfStreets(int northMost, int southMost)

This tests whether a robot is outside given range of streets.

For this version of the method, you use use the logical operator OR || to check and see if the robot is north of the northmost street, or south of the southmost street, and if so, return true. Otherwise, return false.

When you get done with this exercise, show your Instructor.