AP Computer Science A

Karel J. Robot Lab #5

Program Files:

Objective:

Pair Programming

Individual Problem Statements:

Problem #1:

Problem #2:

Problem #3-Optional:

Question #1:

Objective:  

This lab explores instance data and data types

Pair Programming

Karel should double the amount of beepers on a corner (located right in front of it).  Assume that there is a finite number of beepers on the corner and karel starts with an infinite number of beepers in his beeper bag.  Karel should create a second pile of beepers that doubles the amount of beepers present on the corner in from of it.  

Initial State                        Final State


Individual Problem Statements:

Problem #1:

There is a menace in Karel’s world--an infinite pile of beepers!  If Karel accidentally tries to pick up an infinite pile of beepers it is forever doomed to pick up beepers from the pile.  The robot is standing outside of two rooms:  one is to the west and one is to the east.  Only one of these rooms has a pile of beepers that karel can pick.  The other room has an infinite pile of beepers.  To help the robot decide, Karel is currently standing on a pile of beepers.  If the pile of beepers is even, the same room is on the east.  If the pile of beepers is odd, the safe room is to the west.  Write a program in which karel correctly enters the safe room and picks the entire pile of beepers.

Problem #2:

Program Karel to go on a treasure hunt.  The treasure is marked by a corner containing five beepers.  Other corners (including the corner in which karel starts) contain clues, where each clue indicates the direction karel should proceed.  Karel begins at the corner of 2nd Street and Second Ave.  The clues are as follows:  1 beeper means karel should go north, 2 means east, 3 means south, 4 means west.  Karel should follow the clues until it reaches the treasure corner where the robot should turn itself off.  Below is a possible treasure hunt.  You can assume that Karel starts on the corner of 2nd Avenue and 2nd Street


Problem #3-Optional:

Karel has been tasked with “cleaning up” a voting ballot according to the following rules:

  1. If a beeper is present on 3rd street, the adjacent “rooms” must each contain one beeper.
  2. If no beeper is present on 3rd street, then each adjacent “room” cannot contain any beepers.  
  3. Use the world below, but make your solution general enough to work for any situation (you may assume there are  5 pairs of adjacent rooms and karel starts at 1st Ave and 3rd street facing east.

Question #1:

What does modular arithmetic allow you to do?  How does it work with negative numbers?