1 Note: Original slides provided by www.apComputerScience.com and modified for Mr. Smith’s AP Computer Science A classwww.apComputerScience.com.

Slides:



Advertisements
Similar presentations
1 Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science A classwww.apComputerScience.com.
Advertisements

Copyright, Joseph Bergin
Chapter 3 Extending the Robot Programming Language.
1 eclipse Tips. 2 What is eclipse? Eclipse is a popular IDE (Integrated Development Environment) that we will use to create, compile, execute, and test.
How to Create a Java program CS115 Fall George Koutsogiannakis.
Karel The Robot In the beginning… software. Karel the Robot  All robots are controlled by software  Artificially intelligent robots that can “think”
Conditionals How do we solve tasks in which every particular of a task is not specifically known? – A robot needs the ability to survey its immediate environment.
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.
1. 2 Chapter 1 Introduction to Computers, Programs, and Java.
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.
1 eclipse Tips. 2 What is eclipse? Eclipse is a popular IDE (Integrated Development Environment) that we will use to create, compile, execute, and test.
Chapter 5 Conditionally Executing Instructions
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 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.
Session One Introduction. Personal Introduction Role of programmers Robot Examination HUD & HID Uploading Code.
Karel J. Robot A Gentle Introduction to the Art of Object Oriented Programming.
Karel the Robot A Gentle Introduction to the Art of Programming.
JAVA BASICS: Variables and References SYNTAX, ERRORS, AND DEBUGGING.
Programming Errors Lexical errors – occur whenever Karel reads a word that is not in his vocabulary. Example in English: We are asking directions and instead.
Thanks to Dr. Kris Schindler for this (and all Karel the Robot slides)
Copyright © Curt Hill Turtles The beginning of media computation.
What does a computer program look like: a general overview.
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
Introduction to programming in the Java programming language.
Karel J. Robot Tool for learning OOP (Lecture covers Ch. 1 and 2)
1 Karel – Chapter 6 Instructions That Repeat Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science.
1 Karel – Chapter 5 Conditionally Executing Instructions Note: Original slides provided by and modified for Mr. Smith’s AP Computer.
Identifiers Identifiers in Java are composed of a series of letters and digits where the first character must be a letter. –Identifiers should help to.
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.
Introduction to Computer Science
Ch. 2 1 Karel – Primitive Instructions Basic tools with which all problems are solved (analogies: carpentry, geometry) –move() –turnLeft() –putBeeper()
Objective You will be able to define the basic concepts of object-oriented programming with emphasis on objects and classes by taking notes, seeing examples,
CS116 COMPILER ERRORS George Koutsogiannakis 1. How to work with compiler Errors The Compiler provide error messages to help you debug your code. The.
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 6 Instructions That Repeat Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science.
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.
Compiler Errors Syntax error Lexical Can not resolve/find symbol Can not be applied Execution error Oh wait, a run time error Intent error It ran, but.
Karel the Robot – Review Primitive Commands move pickbeeper putbeeper turnleft Turnoff Karel’s program statements are separated by a semicolon (;) Copyright.
1 Karel J. Robot Chapter 5 Conditionally Executing Instructions.
Chapter 3 Extending the Robot Programming Language.
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
Chapter 1 Introduction to Computers, Programs, and Java
GC101 Introduction to computer and program
Eric Roberts and Jerry Cain
Copyright © 2008 by Helene G. Kershner
Copyright © 2008 by Helene G. Kershner
Karel J Robot.
Karel – Primitive Instructions
Karel J Robot.
Karel the Robot – Making Decisions
slides courtesy of Eric Roberts
A Gentle Introduction to the Art of Object Oriented Programming
Lecture Notes - Week 2 Lecture-1. Lecture Notes - Week 2 Lecture-1.
Karel – Primitive Instructions
Presentation transcript:

1 Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science A classwww.apComputerScience.com

2 The robot executes an instruction by performing the instruction’s associated action or actions The robot executes a program by performing a sequence of instructions given to it Instructions are executed one at a time in the order that they are listed

3 Basic tools with which all problems are solved. An analogy is when a carpenter performs primitive tasks such as hammering, leveling, measuring, sawing, etc. He can accomplish all his carpentry tasks (some which are very complicated) using these basic tasks. In Java, each of these primitive instructions is called a method. A standard robot has these five methods: –move() –turnLeft() –putBeeper() –pickBeeper() –turnOff()

4 object.method1(); object.method2(); -A method acts on the object. It is the message sent to the object. -Objects are typically nouns (e.g., karel). They either do something or remember something. -Methods are typically verbs (e.g., move) and represent behavior Example: karel.move() object method

5 Moves forward one block in the direction that it is facing (it will not move sideways) Continues to face the same direction “Error Shutoff” if trying to move into a wall or boundary (Ouch! Look first!)

6 Stays at same corner (does not alter location) Turns 90 degrees to the left Cannot cause an error shutoff Note: There is no turnRight() instruction

7 Picks up a single beeper on the current corner and places it in beeper bag It only picks up one beeper, even if there are multiple beepers on the corner If attempted on a beeper-less corner, it causes an error shutoff

8 Takes beeper from beeper bag and puts it down on current corner It only puts down one beeper, even if there are multiple beepers in beeper bag If attempted with an empty beeper bag, it causes an error shutoff

9 Robot turns off and is incapable of executing another instruction until restarted This is the last instruction executed on a robot object After turnOff() is executed, all other instructions are ignored

10 UrRobot class (the “Model-T” Robot) public class UrRobot { void move() {…} void turnOff() {…} void turnLeft() {…} void pickBeeper() {…} void putBeeper() {…} } “primitive” You can’t/don’t need to define this class – it is in a library for you to use Did you know that in German “Ur” means “original” or “primitive”?

11 A class is not a robot. It is a description of robots of the same kind. The simple model of the robot described above is the UrRobot class By convention classes begin with a capital letter A class is like a production line in a factory that makes the same robots

12 import kareltherobot.*; public class KarelSample implements Directions { public static void main(String args[ ]) { UrRobot karel = new UrRobot(2, 1, East, 1); karel.move(); karel.turnLeft(); karel.putBeeper(); karel.move(); karel.turnOff(); } static { World.setVisible(true); World.showSpeedControl(true); } Names for this type of program are: Client program, Driver program, Tester program

13

14 Copying Classes between School and Home Since there are times when you will want to continue your work at home, you will need to be able to transfer your code back and forth. This is where your flash drive becomes handy. To reduce confusion, keep the folder structure on your flash drive the same as the folder structure on H:\workspace. Use file manager to locate the Java source file (that has extension.java) within the package folder. Copy only the.java files (not the.class files) to your flash drive folder. You can then copy these files to your package folder on your destination computer. Note: After you launch eclipse, it is important to refresh the project and package. Otherwise, the new code may not be seen within eclipse: –Single click on the project and select File > Refresh (or press F5). –Single click on the package and select File > Refresh (or press F5).

15 Classes begin with capital letters (i.e. UrRobot). Methods, objects, and variable names begin with lower case (camelCase) Use indentation to line up statements Brackets {} should be on a line by themselves Use comments // to identify what the code is supposed to do (very useful)

16 A Definition of Symbol: A symbol is a written word or sequence of characters used to represent something else. Special symbols: ; { }. (they mean something special in Java) Names are symbols: karel, UrRobot, putBeeper. UrRobot is not a robot itself, but represents a type of robot. Reserved words are symbols: class, void, new (they have a built-in purpose) Note: Symbols must match in case when used in Java programs (i.e. karel is not the same as Karel and putBeeper is not the same as PutBeeper)

17 (Errors are referred to as bugs) lexical error (compiler catches) –word not in its dictionary (i.e. you type MOVE() instead of move() ) syntax error (compiler catches) –incorrect grammar, punctuation, incorrect location of a statement (i.e. leaving out a parenthesis or using a colon instead of semi-colon) execution error (run-time environment catches) –can’t perform what you ask (i.e. error shutoff if performing move() when a wall is in the way) intent error (logic - guess who catches this one!) –program terminates successfully – junk output, however (i.e. moving robot to the wrong corner) Which is the hardest type of error to correct? Why?

18 public Class SampleTest implements Directions { public static void main(String args[] { UrRobot karel = New UrRobot(2, 1, East, 0). karel.move(); karel.turnLeft() getBeeper(); karel.Move(); karel.turnOff; karel.move(); } IDENTIFY THE BUGS (Clue: There are at least 9 errors)

19 public class SampleTest implements Directions 1) should be class instead of Class { public static void main(String args[]) 2) needs parentheses { UrRobot karel = new UrRobot(2, 1, East, 0);. 3) should be new instead of New 4) use semi-colon instead of period karel.move(); karel.turnLeft(); 5) needs a semi-colon on end karel.pickBeeper(); 6) needs an object and is named pickBeeper karel.move(); 7) Move is not a method karel.turnOff(); 8) needs () (i.e. turnOff() ); karel.move(); 9) can’t perform move after turnOff } } IDENTIFY THE BUGS SOLUTION public Class SampleTest implements Directions { public static void main(String args[] { UrRobot karel = New UrRobot(2, 1, East, 0). karel.move(); karel.turnLeft() getBeeper(); karel.Move(); karel.turnOff; karel.move(); } }

20 Now You Try Writing a Short Program to Draw a Specific Letter Show the homework assignment instructions Show the starting point class from my website Make sure that class is named with your name on the end (DrawE_JoeSmith.java) Show the desired output Review how to copy files from school to home Take a little time to think about the best approach before jumping into the code. It may help to sketch the robot’s path on a sheet of paper.

21 Let’s go into eclipse and begin writing DrawH. We’ll cover these items: –Your workspace/project/package structure –Creating (Copying) the DrawH class. Copy the starting code from my website. –Name the DrawH class to include your name (DrawH_JohnDoe). Click on the DrawH class within Package Explorer and select File > Rename. –Compiling (save) vs. Executing (run) –Copying programs between school and home