DOC PREVIEW
Gordon CS 112 - Introduction to Karel J. Robot

This preview shows page 1-2 out of 6 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS112 Lecture: Introduction to Karel J. RobotLast revised 1/8/09Objectives:1. To introduce Karel J. Robot as an example of an object-oriented system.2. To explain the mechanics of writing simple Karel programs.Materials:1. Interactive demonstration program (Helicopter)2. BlueJ project containing InitialDemo.world,.java and HarvestTwoRows.world, .java3. Projectable version of problem 2-5 from complete book, plus Problem2_5.world4. Projectable version of problem 2-7 from complete book, plus Problem2_7.worldI. IntroductionA. Before beginning our study of Java, we will look at a simpler example of an object-oriented system: Karel J. Robot. By so doing, we will be able to cover many of the key ideas of object-oriented programming in an initial way.B. Karel the Robot was first introduced over 25 years ago as a vehicle for introducing students to programming, at a time when the dominant language for teaching programming was Pascal. It has been revised several times since then. The current version - called Karel J. Robot - is programmed using Java, and runs using a robot simulator, also written in Java.C. We are using this for first few classes of the course to get a quick look at a number of key programming concepts. We will then explore these concepts (and others) in more depth in the rest of the course.II. Introduction to the Robots’ WorldA. As you saw last semester and/or read in the reserve reading, Karel and his relatives are robots who live in a world consisting of east-west Streets and north-south Avenues. At any time, each robot is positioned at the corner of a Street and an Avenue, facing in one of four directions: north, west, south, or east.B. In addition to the streets, avenues, and robots themselves, the robot world includes impenetrable walls and objects called beepers, which robots can pick up from a corner or put down on a corner on command.1DEMO: Run interactive demonstration (Helicopter) using InitialDemo.world as world. Point out streets, avenues, walls, and beepers; then use new button to create a new robot.C. In terms of concepts of object-oriented programming, robots are the objects we are interested in. What about other parts of the system?ASK1. The world, of course, is technically also an object, though a special one because it is a singleton, and, as users, we don’t interact with it directly2. Beepers and walls are not truly objects in the sense we discussed last class. Why?ASKa) Don’t have behaviorb) There is a difference between reality (in which, of course, these are objects) and our software model of reality.D. Robots in this world have five basic capabilities:1. Move forward one square in the direction the robot is facing.2. Turn left 90 degrees.3. Pick up a beeper.4. Put down a beeper5. Turn off upon completing a task.DEMO: Show each operationE. These operations are handled independently by each robot. To get a robot to do something, we must send a specific message to it - e.g. to get a robot called “karel” to move, we must send the messagekarel.move();DEMO: Create a second robot - demo sending messages to one or the other, to both, and to neither. (When a button is pressed in the simulator, the appropriate message is sent to each selected robot.)F. Several of these primitive operations are effective only if certain requirements are met when they are attempted. When a robot is asked to do something it cannot do, it does an error shutoff, which is like a turnoff except that it announces that it has been unable to complete its assigned task. (DEMO EACH FAILURE) 21. Move is permitted only if the robot’s path is not blocked by a wall.2. A robot can only pick up a beeper if there is one on the corner for it to pick up.3. A robot can only put down a beeper on a corner if it has one in its beeper bag.(turnLeft() and turnOff(), however, are always possible.)G. Let’s now consider a demonstration of a single robot performing a complete task.(REFRESH ROBOT WORLD from InitialDemo.world)1. The robot will start at the corner of 1st st and 1st avenue, facing East.2. The robot will go to 2nd and 2nd and pick up the beeper that is there3. The robot will carry the beeper to 3rd and 3rd and drop it off there.4. The robot will return to its starting position.5. The robot will turn off.ASK CLASS TO DEVELOP ONE STEP AT A TIME, AND DEMONSTRATE SIMULATION - BEGINNING WITH CREATING THE ROBOT.III. Robot ProgramsA. Thus far, we have been issuing instructions individually to our robots, using a graphical user interface. In practice, robots are normally given tasks to perform, and then left to perform them.B. A robot program will turn out to be a Java object in its own right, defined by a Java class. (Each program class will be used to create exactly one object, of course.) C. The class defining the program will have two major parts. In the first part - called the main program - we set up the world, construct the program object, and start it executing. In the second part, we order the robot(s) we need and issue instructions to them. The entire program is “wrapped” in some additional statements and punctuation to make it a valid Java program. Part of the form of our programs will also be dictated by some of the requirements of the simulator we will be using in our lab.3D. To produce and run robot programs, we will proceed as follows:1. We will create and run our programs using a very simple integrated development environment (designed specifically for educational use) called BlueJ - in fact, we will use BlueJ throughout this course.BlueJ works with basic units of work called “projects”. In fact, each lab and project you do for the course will be done using its own BlueJ project. DEMO: Start BlueJ, open Karel Intro Lecture project2. We will decide on a name for the program. For reasons relating to the requirements of Java, this name will have to consist of only letters, digits, and the underscore (_), with the first character being a letter. We will follow the convention for class names in Java, because our programs will, in fact, be Java classes.Example: Our initial program will be called InitialDemo3. We will create a class containing the program. (I’ve already done this, so I won’t be able to demonstrate this now, though later we will create a new one). DEMO: Show class InitialDemo on screen - explain structurea) prologue commentb) import statement to get access to simulator, including robot classc)


View Full Document

Gordon CS 112 - Introduction to Karel J. Robot

Documents in this Course
Load more
Download Introduction to Karel J. Robot
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Introduction to Karel J. Robot and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Introduction to Karel J. Robot 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?