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 4.1: Evaluating Boolean Expressions
ICE 4.2: New Methods
Download the file named ICE_4_WORKSHEET.docx from the website.
Work through and answer the questions for both parts. When you are finished with both parts, show your instructor your work.
When you get done with this exercise, go on to the next section.
ICE 4.3: If/Else, canPickThing(), FrontIsClear()
Download the file named ICE_04_If_Else.java 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:
- What do all the "Left" turns have in common?
How could you have your code detect that the robot needs to make a left turn? HINT: is the front clear?
- What do all the "Right" turns have in common?
How could you have your code detect that the robot needs to make a right turn? HINT: 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.