Ice01 Making Decisions: If, If/Else Statements

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 ICE 4.1: Evaluating Boolean Expressions


ICE ICE 4.2: New Methods

Download the file named ICE_4_WORKSHEET.docx or ICE_LECTURE4_WORKSHEET.rtf (if you don't have MS Word) from the website.

Work through and answer the questions for both parts. When you are finished with both parts, show your instructor your work. It's also okay if you want to show your Insttructor one part at a time to see if you are on the right track.

When you get done with this exercise, go on to the next section. Go Next

ICE ICE 4.3: If/Else, canPickThing(), FrontIsClear()

Download the file named from the website.

When you run it, you should see a city that looks like the one below (in jGrasp, you may have to adjust the "Zoom" slider to see everything all at once).


When you examine the code for the program, you'll see that your job is to change goToNextTurn (and ONLY goToNextTurn - you are NOT allowed to change anything else), so that once the program has finished, the robot is at the other end of the pipe (at (4, 17)).

Before you begin, look closely at the City, and then answer these questions:

How could you have your code detect that the robot needs to make a left turn? HINT HINT: is the front clear?

How could you have your code detect that the robot needs to make a right turn? HINTHINT: is the front clear?

Notice how between each call to goToNextTurn the robot is moved ahead four spaces, then goToNextTurn decides which way to turn.

Notice how that last hallway is 8 spaces long.

In this situation, what we need to have happen is for the robot to decide to move 4 spaces instead (or maybe, to turn, but then turn back to the Robot's original facing) before the command gets moved again.

Since this situation is similar to making a right-hand turn, so you might want to put another if…else statement inside the code for your 'figure out that we should turn right' command, in order to distinguish between the two.