Karel J. Robot Tool for learning OOP (Lecture covers Ch. 1 and 2)

Slides:



Advertisements
Similar presentations
1 karel_IF_part1 Conditional Statements Flavor 1: if ( ) { } For now: these are method invokations (see next slide)
Advertisements

Karel – Making More Complex Decisions IF / THEN / ELSE IF THEN BEGIN Instructions END ELSE BEGIN Instructions END Do these when test = False Do these when.
1 Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science A classwww.apComputerScience.com.
1 Note: Original slides provided by and modified for this specific classwww.apComputerScience.com.
1 of 3 Karel Karel is an educational programming language for beginners, created by Richard E. Pattis (currently at Pace University, NY). Pattis used the.
Copyright, Joseph Bergin
Nested If Statements While Loops
You ARE NOT ALLOWED To Copy Files!!!. You ARE NOT ALLOWED To Be Told What to Write in the Program.
1 Inheritance in Java Behind the scenes: new Objects from old.
CMPUT 101 Lab # 2 September 17, :00 – 16:50.
Karel The Robot Nested If Statements While Loops Copyright © 2008 by Helene G. Kershner.
Karel the Robot -- ITERATE Problem Statement: Karel is told to “take a walk around the block!” Revise Algorithm: Define move ahead 5 streets Define turnright.
Karel The Robot In the beginning… software. Karel the Robot  All robots are controlled by software  Artificially intelligent robots that can “think”
Polymorphism Are there different ways to solve the Harvester problem? – Robot teams – instead of one robot to solve a problem, let’s get a team of robots.
Robot? What’s a Robot? Introducing Karel-the-Robot.
Extending the Robot Programming Language In the Robot world 1 mile = 8 blocks Suppose we want a robot to run a marathon (26+ miles)? Does our program have.
Karel JRobot Karel is an educational programming language for beginners, created by Richard E. Pattis (currently at Pace University, NY). Pattis used the.
Chapter 5 Conditionally Executing Instructions
1 karel_part5_loops Iteration (Loops) Loops repeat a set of instructions Two types of loops: –Definite loops ( for ) perform instructions explicit (known)
Ch. 2 1 Karel – Primitive Instructions Basic tools with which all problems are solved (analogies: LeftSpinngingRobot, RightSpinningRobot, GuardRobot, etc)
Karel J Robot An introduction to BlueJ and Object- Oriented Programming.
1 Classes begin with capital letters (i.e. UrRobot). Methods, objects, and variable names begin with lower case (camelCase) Use indentation to line up.
1 Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science A classwww.apComputerScience.com.
1 Ch. 7 Recursion similar to iteration in that you repeatedly do a little bit of the task and then “loop” again and work on a smaller piece - eventually.
Karel J. Robot A Gentle Introduction to the Art of Object Oriented Programming.
Karel the Robot A Gentle Introduction to the Art of Programming.
Thanks to Dr. Kris Schindler for this (and all Karel the Robot slides)
1 karel_part2_Inheritance Extending Robots Tired of writing turnRight every time you start a new karel project. How do we avoid re-writing code all the.
1 Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science A classwww.apComputerScience.com If you.
1 Karel – Chapter 5 Conditionally Executing Instructions Note: Original slides provided by and modified for Mr. Smith’s AP Computer.
Karel the Robot A Gentle Introduction to the Art of Object- Oriented Programming in Java.
1 Note: Original slides provided by and modified for Mr. Heath’s AP Computer Science A classwww.apComputerScience.com.
1 Karel J Robot OOP approach to learning computer science “Its study involves development of the ability to abstract the essential features of a problem.
Georgia Institute of Technology Simulations Barb Ericson Jan 2005.
15-100: Introduction to Programming w/ Java * Ananda Gunawardena -- Lecture – School of Computer Science – Phone : (x81559) – Office: Wean Hall.
Chapter 5.  We’ve been using UrRobot – knows only 5 things  Let’s now use a new type of Robot: Robot!  i.e. – public class MileMover extends Robot.
Introduction to OOP in VB.NET using Robots ACSE Conference, Nov 2004 Michael Devoy Monsignor Doyle C.S.S., Cambridge
1 Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science A classwww.apComputerScience.com Day 4.
Extending Karel’s Vocabulary This PPT originated with Dr. Judy Hankins Modifications have been done by Dr. Untch & Dr. Cripps.
1 Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science A classwww.apComputerScience.com.
Introduction to Computer Science
Ch. 2 1 Karel – Primitive Instructions Basic tools with which all problems are solved (analogies: carpentry, geometry) –move() –turnLeft() –putBeeper()
Mile-long hurdle race Suppose that we want to program Karel to run a one-mile long hurdle race, where vertical wall sections represent hurdles. The hurdles.
Karel the Robot – Review Primitive Commands move pickbeeper putbeeper turnleft turnoff Karel’s program statements are separated by a semicolon (;) Copyright.
1 Karel – Chapter 5 Conditionally Executing Instructions Note: Original slides provided by and modified for Mr. Smith’s AP Computer.
1 Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science A classwww.apComputerScience.com.
Karel the Robot – Review Primitive Commands move pickbeeper putbeeper turnleft Turnoff Karel’s program statements are separated by a semicolon (;) Copyright.
Karel the Robot – Review Primitive Commands move pickbeeper putbeeper turnleft Turnoff Karel’s program statements are separated by a semicolon (;) Copyright.
CS 106A, Lecture 3 Problem-solving with Karel
Karel – Primitive Instructions
Mile-long hurdle race Suppose that we want to program Karel to run a one-mile long hurdle race, where vertical wall sections represent hurdles. The hurdles.
In the beginning… software
Copyright © 2008 by Helene G. Kershner
Loops We have already seen instances where a robot needs to repeat instructions to perform a task turnRight(); moveMile(); Harvesting beepers in a field.
Copyright © 2008 by Helene G. Kershner
Karel J Robot.
karel_part4_functions_2
Polymorphism and Observers
Karel – Primitive Instructions
Karel J Robot.
CS 106A, Lecture 2 Programming with Karel
Polymorphism Simple but profound!.
Karel J Robot OOP approach to learning computer science
Karel the Robot – Making Decisions
A Gentle Introduction to the Art of Object Oriented Programming
Karel J Robot OOP approach to learning computer science
Object References a.k.a. variables
Nested If Statements While Loops
CSE 111 Karel the Robot.
Karel – Primitive Instructions
Presentation transcript:

Karel J. Robot Tool for learning OOP (Lecture covers Ch. 1 and 2)

Karel’s World Imaginary 2D world Streets (E,W) AvenuesAvenues Streets AvenuesAvenues NSNS

Karel’s World (for right now) only two things can exist in the world: Robots Beepers Robots can pick up beepers and place them in their “beeper bag.” Robots can also put one or more beepers down as long as it has enough beepers in its bag.

Karel’s World Robots and Beepers can only be placed on corners in the world. More than 1 beeper/robot per corner is possible Robot’s can face N, E, S, or W

Karel’s World Robots can only do 4 things in the world. There is a specific command (i.e. method) for each action: move() turnLeft() pickBeeper() putBeeper() turnOff()

Karel’s World For a Robot to enter the world, it must be constructed in the “Robot Factory.” It is then magically flown to a location specified in its construction. When you construct a robot you must specify: Starting Street Starting Avenue Starting Direction Initial number of Beepers in “Bag”

Constructing a Robot We are going to construct a version of a robot called a UrRobot (historical reasons). Example: UrRobot bob = new UrRobot(2, 4, East, 4); Constructs a new UrRobot at street 2, avenue 4, facing East, with 4 beepers in his bag. “bob” is the name we’re giving this instance of a UrRobot. We can make as many UrRobots as we want, but they each must have names…

Making Robots do stuff Since we named our UrRobot “bob,” if we want him to do something we have to explicitly tell “bob” to do it. Example: bob.move(); This will move bob one block in the direction he happens to be facing. bob.turnLeft(); This will make bob turn 90 degrees to his left bob.pickBeeper(); Bob will attempt to pick up beeper from corner he’s standing on. ERROR if no beeper actually there.

See some real code in action Baker: Go to BlueJ…BlueJ…

Problem A Robot karel starts at 1,1 facing North with a lot of beepers in his bag (let’s say 20). Your task is to make karel draw the letter “H” by placing beepers into the world as shown in the diagram. Karel must end up back at 1,1 facing North This must be done as efficiently as possible. See Handout…