Header

divider
Links
• Home
• Contact Me
• 
Aeries Portal
• Royal High School
• Simi Valley USD

divider

AP Statistics

• Course Calendar
• Chapter Notes
• Practice Tests
• Statistics Links

divider
AP Comp-Sci
 Course Content
• Programs
• Practice Tests
• Comp-Sci Links

divider

CP Statistics
• Course Calendar
• Chapter Notes
• Practice Tests
• Statistics Links


divider

Algebra
• Table of Contents
Geometry
• Table of Contents

Math Power
• Table of Contents

Computer Programming Unit 0 Programs
Karel J Robot


Program 1-1: THS Beeper Parking Task
Your task is to have Karel pick up the 3 beepers in the world, then "park" them in the "garages" as shown. He must also park himself, as shown. See the initial and final situations below. Karel may be faced in any direction when parked.

Initial Situation                                    Final Situation

THS1       THS2

World File: first.wld                                                             BACK TO KAREL MAIN


Program 2-1: The Newspaper Retrieval Task
Every morning Karel is awakened in bed when the newspaper, represented by a beeper, is thrown on the front porch of his house. Program Karel to retrieve the paper  and bring it back to bed. See the initial situation below.

Newspaper Task

World File: fig2-8.kwld                                                                BACK TO KAREL MAIN

Program 2-2: Plant the Flag!
Karel has to scale a mountain, plant a flag, then descend the mountain on the other side. Karel must begin the task with a flag-beeper in his beeper bag. Karel must also follow the path shown in the diagram below - he is climbing, not flying!

Mountain

Initial Situation                                Final Situation

World File: fig2-9.kwld                                                                      BACK TO KAREL MAIN

Program 2-3: The Leaky Shopping Bag
On the way home from grocery shopping, Karel's bag ripped open, leaking a few items. The items are represented by - you guessed it - beepers. Karel needs to go back and pick these items up and return to his starting position. See the initial situation below.

shopping bag

               

World File: fig2-10.kwld                                                                     BACK TO KAREL MAIN

Program 2-4: The Rearranger
Karel must rearrange a column of beepers into a row of beepers. This requires picking the beepers up, then placing back down as seen in the example Note that the middle beeper does not change position. See the initial and final situations below.

beepers

World File:fig2-11.kwld                                                                     BACK TO KAREL MAIN

Program 2-5: The Initializer
Karel must spell out your inititals using beepers. Make the initials at least 5 beepers high. See below for an example using my initials, DRS. Start with an infinite number of beepers (recall that is done with a -1).

initials          

World File: blank2.kwld                                                                         BACK TO KAREL MAIN

 

Program 3-1: The StairClimber Class
Karel must learn to climb stairs, picking up a beeper from each step. See the initial and final situations below.

  

World File: fig3-1.kwld                                                                     BACK TO KAREL MAIN

Program 3-2: The ShelfStocker Class
Karel just got a new job stocking grocery store shelves. He has to take the items off of the floor and place them on the shelf. He should begin and end the task at (1,1). See the initial and final situations below.

          

World File: shelf.kwld                                                                     BACK TO KAREL MAIN

Program 3-3: The Harvester Class
Karel must “harvest” a field of beepers. Each row of will consist of 5 beepers, and the number of rows will always be an even number. See the initial and final situations below.

          

               

World File: fig3-2.kwld                                                                     BACK TO KAREL MAIN

Program 3-4: The Planter Class
Karel will be planting flowers in planter boxes. He will pick up 3 plants at the bottom of each planter box and then place them in a column in the boxes as shown in the example task below. Karel begins the task at (1, 1) facing East.

           


World File:
planter.kwld                                                                       BACK TO KAREL MAIN

Program 3-5: The Mover Class
Karel is rearranging office furniture. he needs to move employees desks from one cubicle to the one adjacent to it. He will then move on and do the next desk, etc... . Beginning and ending situations are as shown below. Karel begins the task at (1, 3) facing East.

          

World File: mover.kwld                                                                         BACK TO KAREL MAIN

Program 3-6: The Pinsetter Class
Karel just got a job as a pinsetter at the local bowling alley. His job requires him to set up 10 pins in the normal configuration. See the initial and final situations below.


World File:
blank.kwld                                                                     BACK TO KAREL MAIN

 

Program 4-1: The Hurdler Class (focus on if statements)
Karel must run a hurdle race, jumping over hurdles or running straight when no hurdle is present. There will be at most, 8 hurdles, so the race is 8 blocks long (the race always ends at 1 st Street and 9 th Avenue. However, the arrangement of the hurdles can change from race to race. So be sure that your hurdler can run any such race. See the example initial and final situations below.

World File: hurdles.kwld                                                            BACK TO KAREL MAIN

Program 4-2: The CarpetLayer Class
Karel has a new job, carpeting rooms along an 8-block section of his world. A room is a “two-space” column that is enclosed by wall segments to the west, north and east. The door is to the south. Karel is to place a beeper in each space of the room. He begins the job with an infinite number of beepers in his bag. As with the previous tasks, Karel should be able to carpet any such 8-block section. See the example initial and final situations below.

          

               

World File: carpet.kwld                                                                      BACK TO KAREL MAIN

Program 4-3: The ColumnHarvester
Karel must now harvest up to 8 columns of beepers. There are exactly 3 beepers in any given column. Again, it is necessary to program Karel so that he can harvest any such field, not just the one in the example. See the example initial and final situations below. Karel begins the task at (1,1), facing East.

columns
           

World File: columns.kwld                                                                  BACK TO KAREL MAIN

Program 4-4: The Stacker
Karel needs to complete “stacks” of beepers – three high. He begins at (1, 1) and checks to see if there is a beeper there. If there is, he completes the stack by adding two more beepers on top, for a total of three. If there is no beeper there, he does nothing and moves on. He completes his task when he has reached (1, 8) and completed all necessary stacks. See an example initial and final situation below.

      Initial Situation                                             Final Situation

          stacker1      stacker2     

World File: stacks.kwld                                                                        BACK TO KAREL MAIN

Program 4-5: The PlaceSetter
Karel needs to set a “place” (two beepers), anywhere there is a table (wall) to his left. He begins at (1, 1) and checks to see if there is a wall to his left. If there is, he sets the place by putting two beepers at the current location. If there is no wall to the left, he does nothing and moves on. He completes his task when he has reached (1, 8) and set all necessary places. See an example initial and final situation below.

      Initial Situation                                                Final Situation

    places1       places2
           

World File: places.kwld                                                                  BACK TO KAREL MAIN

Program 4-6: The ChainMaker Class
Karel has been assigned the task of completing a chain of beepers. The chain is 5 blocks long and each link must contain 2 beepers. He begins the job with 10 beepers in his bag. See the example initial and final situations below. Karel begins the task at (1,1), facing East.

      Initial Situation                                            Final Situation

         

World File: chain.kwld                                                                        BACK TO KAREL MAIN

Program 4-7: The EggPicker Class (focus on the AND operator)
Karel has now been hired to pick eggs and place them in cartons. The role of the egg will be played by our versatile beeper. An egg is ready to be picked as long as a hen is not sitting on it (hens are characterized by horizontal walls). Karel must walk the hallway of the chicken coop, which is along 1 st street. If there is an egg in any given cage in the coop, he pick it up as long as a hen is not sitting on it. When finished, Karel should go to 3rd Street and 1 st Avenue, which is where the eggs will be placed in cartons, and shut off. As with the previous tasks, Karel should be able to pick eggs in any such arrangement. See the example initial and final situations below.

 

          

World File: eggs.kwld                                                                         BACK TO KAREL MAIN

Program 4-8: The TopOff Class
Karel will now go down first street and "top off" any beepers that he encounters in the first 8 blocks. Topping off involves putting a beeper on top of any existent beeper that is there. One catch - Karel can only start the task with 5 beepers. So when he runs out of beepers, he can no longer "top off," even when he encounters a beeper that needs "topping off." See the example initial and final situations below.

     topoff_1           topoff_2

World File: topoff.kwld                                                             BACK TO KAREL MAIN

 

Program 5-1: The Steeplechaser Class (focus on FOR loops)
Karel must run a steeplechase race, jumping over steeples and picking up beepers as he goes. There will be exactly 8 steeples and beepers, so the race is 8 blocks long (the race always ends at 1st Street and 9th Avenue. See the initial and final situations below.

              

World File: steeple2.kwld                                                                BACK TO KAREL MAIN

Program 5-2: The DiagonalMaker Class (focus on FOR loops)
Karel must make a diagonal of beepers of a length dictated by the programmer. For example, if the programmer asks for 5 beepers, the diagonal will be of length 5. See the example initial and final situations below.


           

World File: blank.kwld                                                                      BACK TO KAREL MAIN

Program 5-3: The PostMaker Class (focus on FOR loops)
Karel has been hired to build "posts" of 4 beepers high. He is told how many posts to install and then he does it. See the example below for a task of 5 posts.

pre           post_post               

World File: blank.kwld                                                                     BACK TO KAREL MAIN

Program 5-4: The PyramidMaker Class (focus on FOR loops)
Karel must make a "pyramid" of beepers of a height dictated by the programmer. For example, if the programmer asks for a pyramid 5 beepers high, the final stack will contain 5 beepers. See the example initial and final situations below.


           pyramid

World File: blank.kwld  

Program 5-5: The SquareMaker Class (focus on FOR loops)
Karel has been hired to build square rooms out of beepers. He is given instructions by you, the programmer, to go to a given location and build a room of a given size. In the example below, he was told to go to (2, 3) and build a room of size 4. It is to be assumed that Karel begins each task at the Origin, facing East, with an infinite number of beepers in his bag.

xcxc               

World File: blank.kwld                                                                     BACK TO KAREL MAIN

Program 5-6: The Fetcher Class (focus on WHILE loops)
It’s Karel the robot dog! He can fetch a ball (beeper, of course) but he can’t run directly to it. He has to stick to East-West, North-South movement. He begins his little game at the origin, facing East. To help him out, we place a wall at the point where he needs to turn. He then turns and runs to the place where the ball is. Finally, he must return to the origin and drop the ball off to his master. Below is a sample situation. Your task should be able to handle any such situation.

                

World File: fetch.kwld                                                                     BACK TO KAREL MAIN

Program 5-7: The Tiler Class (focus on WHILE loops)
Now our robot hero will be charged with laying ceramic tile in some rooms in a building. He will begin at the opening to a hallway, then go to each room and tile each available square in the room with a beeper. When he reaches the end of the hallway, he is to return to the entrance to the hallway where he started out. The robot should begin the task with an infinite number of beepers. Below is a sample building. Your task should be able to tile any such building.

    

World File: tiler.kwld                                                                         BACK TO KAREL MAIN

Program 5-8: The TrashCollector Class (focus on WHILE loops)
Karel is now employed by the city sanitation department. He has to collect all of the trash cans on 1st street. The number of houses on the street is unknown, but the end of the street is marked by a wall. He has to empty all trash cans (beepers) at each house. Each house has at least one trash can, but the number varies. It is to be assumed that Karel begins the task at the origin, facing East and the first house is directly in front of him. When finished, Karel should return all beepers to the origin, dump them there and turn himself off. See the example task below.

             

World File: trash.kwld                                                                       BACK TO KAREL MAIN

Program 5-9: The Connecter Class (focus on WHILE loops)
Karel will now connect a collection of 4 beepers by moving toward them and leaving a trail of beepers as he goes. Every time he encounters a beeper, he should turn left and repeat the process, until he has connect all 4 beepers. He ends by going back to the origin and facing North. See the example task below.

connect_pre          connect_post

World File: connect.kwld                                                                       BACK TO KAREL MAIN

Program 5-10: The Columner Class (focus on WHILE loops)
Karel will cruise down 1st Street looking for stacks of beepers. When he encounters a stack, he will pick them all up and make a column out of the entire stack. He is done making columns when he encounters a vertical wall on the street. Have him end the task by jumping over the wall. For this task, make your own sample world and save it in your classes folder. See the example task below.

columner_pre           columner_pre  

World File: stacks.kwld                                                                       BACK TO KAREL MAIN

Program 5-11: The Beeplechaser Class (focus on WHILE loops)
Karel will now run a different type of steeple chase in which the steeples are made of beepers. Instead of jumping the steeples, the robot picks them up. Each steeple is made up of columns of beepers that are of unknown height. Also, the number of steeples is unknown and they are placed in random locations. The race begins at (1,1) and ends at (1,9). The world will be clear of all beepers when the race is finished. For this task, make your own sample world and save it in your classes folder. See the example race below.

 

beeples

             

World File: beeples.kwld                                                                       BACK TO KAREL MAIN


 






Home  •  About Me  •  Aeries Portal  •  Contact Me
© DanShuster.com