Karel Primitive Instructions - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Karel Primitive Instructions

Description:

intent error (logic - guess who catches this one! ... Have the robot 'print' (using beepers) the letter H (with 3-beeper sides and a 1 ... – PowerPoint PPT presentation

Number of Views:25
Avg rating:3.0/5.0
Slides: 13
Provided by: davidw121
Category:

less

Transcript and Presenter's Notes

Title: Karel Primitive Instructions


1
Karel Primitive Instructions
  • Basic tools with which all problems are solved
    (analogies carpentry, geometry)
  • move()
  • turnLeft()
  • putBeeper()
  • pickBeeper()
  • turnOff()

2
OOP -ness
  • object.method1()
  • object.method2()
  • -where a method acts on the object
  • -objects are typically nouns (e.g., karel)
  • -methods are typically verbs (e.g., move) and
    represent behavior
  • karel.move()

3
move()
  • forward only, one block
  • Error Shutoff if trying to move into a wall (a
    duh! Look first!) Remember C and div by zero???

4
turnLeft()
  • stay at same corner
  • turn 90 degrees to the left
  • cannot cause an error shutoff

5
pickBeeper()
  • picks up beeper on current corner and places in
    beeper bag
  • attempted on beeper-less corners causes an error
    shutoff

6
putBeeper()
  • take beeper from beeper bag and put down on
    current corner
  • attempted with an empty beeper bag causes an
    error shutoff

7
turnOff()
  • robot turns off and is incapable of executing
    another instruction until restarted
  • the last instruction executed on a robot object

8
Description
public class ur_Robot void move() void
turnOff() void turnLeft() void
pickBeeper() void putBeeper()
  • ur_Robot class (the Model-T Robot)

primitive You cant/dont need to define this
class it is in a library for you to use
9
Sample Program
  • import kareltherobot.
  • public class SampleTest implements Directions
  • public static void main(String args)
  • ur_Robot karel new ur_Robot(2, 1, East, 0)
  • karel.move()
  • karel.move()
  • karel.turnLeft()
  • karel.turnOff()
  • static
  • // code here that you need not worry much
    about

10
Error Classification
  • 4-types
  • lexical error (compiler catches)
  • word not in its dictionary
  • syntax error (compiler catches)
  • incorrect grammar, punctuation, incorrect
    location of a statement
  • execution error (run-time environment catches)
  • cant perform what you ask (at run-time)
  • intent error (logic - guess who catches this
    one!)
  • program terminates successfully junk output,
    however

Which is the hardest type of error to correct?
Why?
11
Now You Try a Short Program on Paper 10 minutes
  • start a robot (HBot) at position (1, 1) (a.k.a,
    the origin) facing North and having an infinite
    number of beepers
  • Have the robot print (using beepers) the letter
    H (with 3-beeper sides and a 1-beeper bar)
  • when done, the robot should be facing North back
    at the origin (leaving the world in its original
    state of being)

12
Programming the HBot together
  • Lets go into BlueJ and write the HBot. Well
    cover these items
  • Your network drive and staying organized
  • Creating a workspace
  • Using/reading the API
  • Compile vs. Execute
  • www.apcomputerscience.com/bluej and setting up
    things at home
Write a Comment
User Comments (0)
About PowerShow.com