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.

Slides:



Advertisements
Similar presentations
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.
Advertisements

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
1 karel_part4_functions.ppt Functions Functions return values or Objects. –Using a function allows the programmer to focus on other task. –Using a function.
1 Karel J Robot-Lesson 3 NTSD-Mr. Moon Karel J Robot Lesson 3 A Gentle Introduction to the Art of Object-Oriented Programming in Java.
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.
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
Comp 249 Programming Methodology Chapter 8 - Polymorphism Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University, Montreal,
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.
Chapter An Introduction to Problem Solving 1 1 Copyright © 2013, 2010, and 2007, Pearson Education, Inc.
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)
Karel J. Robot Tool for learning OOP (Lecture covers Ch. 1 and 2)
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 Karel – Chapter 6 Instructions That Repeat Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science.
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 CS161 Introduction to Computer Science Topic #9.
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.
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.
Programming in Karel Eric Roberts CS 106A January 6, 2016.
Ch. 2 1 Karel – Primitive Instructions Basic tools with which all problems are solved (analogies: carpentry, geometry) –move() –turnLeft() –putBeeper()
Karel J. Robot Chapter 6 Instructions That Repeat.
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 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.
Alice and Java Unit 7 1. Day 1  Objective: Gain an introduction to Java and Eclipse  Essential skill: DM-1: Use technology to advance critical thinking.
1 Karel J. Robot Chapter 5 Conditionally Executing Instructions.
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.
Eric Roberts and Jerry Cain
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
Karel – Primitive Instructions
Karel J Robot.
CS 106A, Lecture 2 Programming with Karel
Karel J Robot OOP approach to learning computer science
Algorithm The key is the step-by-step instructions.
Karel the Robot – Making Decisions
LESSON 03 Turning In Place. LESSON 03 Turning In Place.
slides courtesy of Eric Roberts
A Gentle Introduction to the Art of Object Oriented Programming
Karel J Robot OOP approach to learning computer science
Unit 1 Test 1 Redo Friday at 8am here or Friday 4th BLOCK in Math Lab
Algorithm The key is the step-by-step instructions.
Nested If Statements While Loops
Karel – Primitive Instructions
Presentation transcript:

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 and its solution, to reason effectively in the abstract plane, without confusion by a mass of highly relevant detail.” (C. Hoare)

2

3 Karel J (the Robot) Robot World –A flat plane of streets (east-west) and avenues (north-south) Corner (many robots may occupy) Avenues Streets

4 Karel’s World (cont’d) Contains Beepers and Walls Beepers –May be picked up, carried, and placed again –May place several on a corner and they don’t interfere with Robot movement

5 Robot Capabilities Move Turn Sense surroundings –hear beepers (on same corner) –Determine direction it is facing Pick up, carry, and put down beepers

6 Tasks & Situations Examples –Move to a corner (3 rd St. & 5 th Ave.) –Run a race –Escape from a maze –Find a beeper and deliver it to the origin

7 Previous task (Karel00) Karel ran a lap around the Block –How many lines of code did you write? 20 (16 move() and 4 turnLeft() ) Was there a pattern? 4 x (4 moves, turnLeft) –Could the code have been written in fewer lines? The answer is “of course”, the process is stepwise refinement.

8 Stepwise Refinement A different design/solution for Karel00 would have been to notice that the Robot perform the same task four times. That is, the Robot was to move four times and turn left. After performing this maneuver four times, the task would have been complete

9 Stepwise Refinement Alternate implementation for Karel00 public void task() { moveForwardTurnLeft(); } Now we must define moveForwardTurnLeft(); public void moveForwardTurnLeft() { move(); turnLeft(); }

10 Stepwise Refinement You are right, moveForwardTurnLeft is two separate tasks, so this method could/should be refined further.

11 Stepwise Refinement Alternate implementation for: moveForwardTurnLeft public void moveForwardTurnLeft() { moveForward(); turnLeft(); } public void moveForward() { move(); }

12 We’re a little wiser Lets apply our new design methodology to the next task: Consider the turnRight() command Our Robot doesn’t understand turnRight(), it is not capable of turning right But turning right make sense.

13 turnRight() Karel doesn’t know how to turn right, so how do we get the robot to turn clockwise 90 degrees? turnLeft three times? Do you want to write three lines of code every time you want to turn right, Or do we write one method called turnRight and invoke this method.

14 Implement turnRight() In your class you would need to include the following method public void turnRight() { turnLeft(); } Wouldn’t it be nice if I did not have to write this code every time we create a new Robot class. The answer is of course there is, but that is a topic for another day.

15 Adding methods Consider the implementation of turnRight() below public void turnRight() { turnLeft(); } –Note the different parts of the method –Heading : public void turnRight() –Beginning : { –Body : turnLeft(); turnLeft(); turnLeft(); –End : }

16 Adding methods –Heading: public void turnRight() –Three parts For now, the first two words are always the same : public void The third word is the name of the method turnRight() –Beginning : { Lets the compiler know that here comes the implementation –Body : turnLeft(); turnLeft(); turnLeft(); The actual commands that in fact replace the method call Every time the Robot (or any Object) sees the new command, it will automatically perform the Body of the new method –End : } Lets the compiler know the implementation is complete

17 Your Task You will copy the Karel01 folder to your work area. The MainDriver constructs: –Two LeftSpinningRobots –Two RightSpinningRobots –Two GuardRobot You will implement the task() for all three Robot classes continue

18 LeftSpinningRobot The task method will have the Robot make three complete revolutions invoking only the turnLeft();

19 RightSpinningRobot The task method will have the Robot make one complete revolution invoking only the turnRight() method.

20 GuardRobot This Robot will march (move()) twice in a rectangular pattern around the SpnningRobots.

21 How to get Started From the K drive –Copy the Karel01 Folder to your workspace. –Open BlueJ Open Project and select Karel01 –Implement the task method for: LeftSpinningRobot RightSpinningRobot GuardRobot

22 Special Notes Why is the RightSpinning Robot turning Left and making more that one revolution. Notice that not all the Robots move at the same time. They move one at a time. That is, they take turns. Do you know how to determine the order that the Robots move?

23 Special Notes What do the last two lines of you file look like? Both ending lines should consist of single } The general class outline should be as follows: public class ClassName() { servalMethods() { }