15-100: Introduction to Programming w/ Java * Ananda Gunawardena -- Lecture – School of Computer Science – Phone : 268-1559 (x81559) – Office: Wean Hall.

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
Chapter 3 Extending the Robot Programming Language.
Programming in Jessica By Joaquin Vila Prepared by Shirley White Illinois State University Applied Computer Science Department.
You ARE NOT ALLOWED To Copy Files!!!. You ARE NOT ALLOWED To Be Told What to Write in the Program.
CMPUT 101 Lab # 2 September 17, :00 – 16:50.
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.
Lecturer: Fintan Costello Welcome to Hdip 001 Introduction to Programming.
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.
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)
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.
Karel the Robot A Gentle Introduction to the Art of Object- Oriented Programming in Java.
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.
Introduction to OOP in VB.NET using Robots ACSE Conference, Nov 2004 Michael Devoy Monsignor Doyle C.S.S., Cambridge
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()
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.
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.
CS 106A, Lecture 3 Problem-solving with Karel
Computer Engineering Department Islamic University of Gaza
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
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 – 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
slides courtesy of Eric Roberts
A Gentle Introduction to the Art of Object Oriented Programming
Karel J Robot OOP approach to learning computer science
Algorithm The key is the step-by-step instructions.
Nested If Statements While Loops
Karel – Primitive Instructions
Presentation transcript:

15-100: Introduction to Programming w/ Java * Ananda Gunawardena -- Lecture – School of Computer Science – Phone : (x81559) – Office: Wean Hall 5113 – Teaching Assistants – Lab Help, Grading – Helen Han ( ) * Modified from Original Lectures by Don Slater

Java – variables, conditionals, loops, arrays – object oriented programming Problem solving skills Time management skills

How to be Successful in this course Attend class Do the homework – they are designed to help you digest the chapter Do the labs (programming assignments) – they are designed to help you learn how to use the concepts covered in the chapter and discussed during lecture – start the labs early, programming assignments ALWAYS take longer than you think they will The material in each session builds on the material from the previous session

Course Web Site All important information about the course is posted at this site… Check it for What is New Syllabus and course policies are posted here… Syllabus Contact information is posted here… Home Assignment information is posted here… Assignments (where you will find links to labs and homework Course materials (lectures and demo code) will be found here… lectures and demos Course Labs can be found … labs Assessment information can be found assessment

Karel the Robot A Java-based language, with a graphical interface, used as a “first-pass” introduction to the concepts we will study in this course We will learn how to write instruction- sets (programs) so that our programmable robots can perform the tasks we give them

A Robot in its World Beeper Robot Wall Avenue Street Corner Origin 1 st St., 1 st Ave. N

The Robot World A great, flat, plane with standard compass points – Bounded on west by infinite wall extending north – Bounded on south by infinite wall extending east Crisscrossing the world are vertical streets and horizontal avenues – A corner is an intersection of a street and avenue – One or more robots can occupy any corner, facing any direction – Both streets and avenues have numbers – Origin is where 1 st St and 1 st Ave intersect – Robots do not have to start from origin

Objects in the Robot World Wall Sections – Positioned between adjacent street corners, blocking a robot’s direct path – Used to represent obstacles around which robots must navigate Beepers – Small plastic cones that emit a quiet beeping noise – Found on street corners; do not interfere with robot movement – Can be carried, picked up and put down by robots – There can be more than one beeper on a corner, and a robot can carry an infinite supply of beepers – Used to represent tasks for the robots to manipulate

Robot Capabilities Robots can move – Forward in the direction it is facing,from corner to corner – Turn in place – Turn itself off Robots can detect – Walls ½ block in front of them – Beepers by being on the same corner as a beeper – Robots on the same corner with it Robots can navigate by detecting the direction it is facing (north, south, east, west) Robots can manipulate beepers – by carrying them, – picking them up, and putting them down, – knowing if it is carrying any

Working with Robots Robots come from the main factory, Karel-Werke – Can supply several different models of robots – We can work with standard model, or provide specifications for a specialized robot When we want a robot to accomplish a task – Describe special features of the robot we want – Provide instructions on how to perform the task The tasks are written in a robot programming language, with its own vocabulary, punctuation marks and grammar

Robot Tasks A task is something we want the robot to do – Escape from an enclosed room that has a door – Find a beeper and deposit it on origin – Escape from a maze A situation is an exact description of what the world looks like – Robot’s current position and direction it is facing? – Location and length of each wall section? – Location of each beeper? – How many beepers in the robots beeper bag? Most situations will be specified by a map or a brief written description

Primitive Instructions Changing position – move: moves forward to next corner if the path is clear error-shutoff if the path is blocked by a wall – turnLeft: pivots 90 degrees to the left (counter-clockwise) stays on the same corner – turnOff: the task is finished; robot turns off and is incapable of executing any new instructions until restarted on another task

Primitive Instructions Manipulating beepers – pickBeeper: attempts to pick up beeper on the corner it is standing an error shutoff if no beeper is there if more than one beeper on the corner the robot picks up only one – putBeeper: attempts to put beeper on the corner it is standing an error shutoff if no beeper in the beeper bag if more than one beeper in the beeper bag the robot puts down only one

A Robot Program – Karel First Figure 2.3 See Fig 2.3 Demo Project

Robot Language Grammar Special symbols – Semi-colon ; at the ending of each robot instruction – Braces { } to group sets or blocks of robot instructions – Period. To show which instructions belong to which robot Identifiers – For robot and class names Reserved words – Used to structure and organize primitive instructions Comments – // single line comments; /* */ multi line comments – Provide explanation of what is going on to other people who read our programs

Programming Errors Execution Errors / Error Shutoffs – Illegal move, putBeeper, or pickBeeper instructions – Also if there is no turnOff at the end of a program – Figure 2.1 Figure 2.1 – See Figure 2.1 Demo Project See Figure 2.1 Demo Project Lexical errors – When a robot encounters an instruction that is not part of its vocabulary mvoe() instead of move(); turnleft() instead of turnLeft() Yes, capitalization counts; the programming language is case sensitive

Programming Errors Syntax errors – Use of incorrect grammar or punctuation A robot instruction missing a semi-colon at the end Intent error – Program seems to run successfully, but does not accomplish the task Task: pickup the beeper, face north, move one block The robot picks up the beeper, and moves ahead two blocks

A task for Two Robots Figure 2.5 See Figure 2.5 Demo Project