logging in or signing up OOPRobots Hannah Download Post to : URL : Related Presentations : Share Add to Flag Embed Email Send to Blogs and Networks Add to Channel Uploaded from authorPOINTLite Insert YouTube videos in PowerPont slides with aS Desktop Copy embed code: (To copy code, click on the text box) Embed: URL: Thumbnail: WordPress Embed Customize Embed The presentation is successfully added In Your Favorites. Views: 45 Category: Entertainment License: All Rights Reserved Like it (0) Dislike it (0) Added: December 31, 2007 This Presentation is Public Favorites: 0 Presentation Description No description available. Comments Posting comment... Premium member Presentation Transcript Programs and Models: Programs and Models Almost all computer programs model some artifact Artifact: product of civilization, either concrete or abstract, simple or complex Model: a simplified representation of something It includes features that are considered important Neglects other features not considered important Models can be more specific representations of other, more general models Features of a model Characteristics of the model that distinguish one particular instance of a model from another Size, color, name, location Referred to as the state of the instance Behaviors of the model that are generally going to be true for all instances of the model The behavior is consistent for that specific model The different behaviors can be grouped into into categories, Generally behaviors are initiated by external forcesObject-Oriented Programming: Object-Oriented Programming The Java programming language uses an object-oriented programming approach to modeling Each model is defined as a class Java programs use multiple instances of different models or classes to solve a problem or perform a task These multiple instances are known as objects Object-Oriented Programming (OOP), then, is the process of solving problems or performing tasks with multiple, interacting objects.Some terminology: Some terminology Every object has state (characteristics) and behavior Reference: any word/phrase that is used to provide access to an object Java uses a references to identify an object Messages: a request for some desired behavior from an object Messages are sent to references, specifying behavior with supporting detailsObjects, behavior, and classes: Objects, behavior, and classes In Java programming, model elements are called objects Objects that share common behavior are grouped into classes Defining a class in Java is writing code that specifies how objects of the class behave or act Once a class has been defined, objects of that class can be created Every object belongs to exactly one class and is an instance of that class Predefined objects and classes Java comes with some classes already defined We will use classes created by other programmers We will create our own classesUse Robots to First Illustrate: Use Robots to First Illustrate Classes Objects Inheritance Basic Java Programming Syntax Control Structures Interfaces Polymorphism Robot Tasks: 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 descriptionModeling a Robot’s Tasks: Modeling a Robot’s Tasks Karel J. Robot We will learn how to write instruction-sets (programs) so that programmable robots can perform tasks we give them Karel is object-oriented so the tasks will be performed using multiple, interacting objects. Robots Position (implicit to become explicit) Directions World Corners (implicit) Streets Avenues Beepers Walls A Robot Program – Karel First: A Robot Program – Karel First RobotDemo1 A Robot in its World: A Robot in its World Beeper Robot Wall Avenue Street Corner Origin 1st St., 1st Ave. NThe Robot World: 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 1st St and 1st Ave intersect Robots do not have to start from originObjects in the Robot World: 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 manipulateState of the Robot: State of the Robot State: those characteristics that are used to describe the current condition of the object All robots look alike The state of the robot that we are initially interested in is Positional (where is it in its world?) Street position Avenue position Direction it is facing Manipulative Beepers it may be carrying Visibility (can it be seen?) Robot Characteristics - State: Robot Characteristics - State Position A robot’s position will be defined by the corner of the World it is sitting on Direction A robot’s direction will be defined by which of the compass points it is facing in the world Number of Beepers it is carrying Visibility A Robot can be hidden from view, but it is still able to be detected by other robots Initially, we are not interested in other characteristics of robots that we might imagine We will later create other models of robots with some other characteristicsDetermining the Robot’s state: Determining the Robot’s state The robot can report its state (accessors) Report what street or avenue it is on -- street(), avenue() Report the direction it is facing -- direction() Report the number of beepers it is carrying -- beepers() Report its visibility -- isVisible() This is undocumented in Bergin’s text… But most IDE’s with context-sensitive help will show you these features Manipulation of the Robot’s state: Manipulation of the Robot’s state Only the visibility can be directly manipulated All other state is manipulated indirectly through the robots interaction and behavior in it’s World In other words, we cannot pick up a robot and place it somewhere else, it has to move to that position The only time we directly manipulate the state of the robot (other than visibility) is when we build or construct the robot Specify street, avenue, direction, and number of beepers being carried Otherwise, we indirectly manipulate state through the messages we send to a robot object A move will change street or avenue A turn will change the direction the robot is facing Beepers can be picked up or put down, changing the number of beepers the robot can carryFundamental Robot Behaviors: Fundamental Robot Behaviors 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 by being on the same corner with other robots 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 Fundamental Robot Behaviors: Fundamental Robot Behaviors 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 Fundamental Robot Methods: Fundamental Robot Methods 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 Changing Visibility -- modifiers setVisibility(boolean): We can make a robot visible or invisble by sending true or false with this message Sending a message: Sending a message To send a message we must specify the object and the behavior for that object A reference to the receiver object A period The message to be sent To send a message to a Robot named Karel: Karel.move(); reference messageLooking at a Java program: Looking at a Java program A task for two Robots TwoRobotDemo Java Programs: Java Programs Many different kinds of Java programs Primarily concerned with Applets and Applications Applets - run in the context of a web browser Applications - stand-alone programs Object-Oriented Programs solve problems with multiple, interacting objects Java programmers define objects by creating classes Generally, a Java class is written in one file, with the same name and the .java prefixThe main() method: The main() method Every Java application (not applet) has to have a main() method that is the starting point of the program IDE’s such as CodeWarrior require that the class with the main be identified Outside of an IDE, the Java application has to be started with the class that has the main methodKarel programs: Karel programs Will typically be applications The class that has the main() method will typically be called Application This Application class will be found in the file Application.javaThe Application class will: The Application class will Open the world that has the task for the robot(s) to perform In either main() Or in an anonymous, static, initializer (more on this later) Instantiate (construct) the robot(s) necessary to complete the task Send the appropriate messages to the robot(s) to perform the tasksJava Syntax Issues: Java Syntax Issues Special symbols Semi-colon ; Separates one instruction from the next Braces { } Group blocks of instructions Period . Show which instructions belong to which robot Identifiers For robot and class names Made up of characters (A..Z, a..z), digits (0..9), and underscore (_) Must start with a character Reserved words Used to structure and organize primitive instructions Comments // single line comments; /* */ multi line comments; /** */ javadoc comments Provide explanation of what is going on to other people who read our programsProgramming Errors: Programming Errors Execution Errors / Error Shutoffs Illegal move, putBeeper, or pickBeeper instructions RobotErrorsDemo 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; Java is case sensitiveProgramming Errors: 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 You do not have the permission to view this presentation. In order to view it, please contact the author of the presentation.
OOPRobots Hannah Download Post to : URL : Related Presentations : Share Add to Flag Embed Email Send to Blogs and Networks Add to Channel Uploaded from authorPOINTLite Insert YouTube videos in PowerPont slides with aS Desktop Copy embed code: (To copy code, click on the text box) Embed: URL: Thumbnail: WordPress Embed Customize Embed The presentation is successfully added In Your Favorites. Views: 45 Category: Entertainment License: All Rights Reserved Like it (0) Dislike it (0) Added: December 31, 2007 This Presentation is Public Favorites: 0 Presentation Description No description available. Comments Posting comment... Premium member Presentation Transcript Programs and Models: Programs and Models Almost all computer programs model some artifact Artifact: product of civilization, either concrete or abstract, simple or complex Model: a simplified representation of something It includes features that are considered important Neglects other features not considered important Models can be more specific representations of other, more general models Features of a model Characteristics of the model that distinguish one particular instance of a model from another Size, color, name, location Referred to as the state of the instance Behaviors of the model that are generally going to be true for all instances of the model The behavior is consistent for that specific model The different behaviors can be grouped into into categories, Generally behaviors are initiated by external forcesObject-Oriented Programming: Object-Oriented Programming The Java programming language uses an object-oriented programming approach to modeling Each model is defined as a class Java programs use multiple instances of different models or classes to solve a problem or perform a task These multiple instances are known as objects Object-Oriented Programming (OOP), then, is the process of solving problems or performing tasks with multiple, interacting objects.Some terminology: Some terminology Every object has state (characteristics) and behavior Reference: any word/phrase that is used to provide access to an object Java uses a references to identify an object Messages: a request for some desired behavior from an object Messages are sent to references, specifying behavior with supporting detailsObjects, behavior, and classes: Objects, behavior, and classes In Java programming, model elements are called objects Objects that share common behavior are grouped into classes Defining a class in Java is writing code that specifies how objects of the class behave or act Once a class has been defined, objects of that class can be created Every object belongs to exactly one class and is an instance of that class Predefined objects and classes Java comes with some classes already defined We will use classes created by other programmers We will create our own classesUse Robots to First Illustrate: Use Robots to First Illustrate Classes Objects Inheritance Basic Java Programming Syntax Control Structures Interfaces Polymorphism Robot Tasks: 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 descriptionModeling a Robot’s Tasks: Modeling a Robot’s Tasks Karel J. Robot We will learn how to write instruction-sets (programs) so that programmable robots can perform tasks we give them Karel is object-oriented so the tasks will be performed using multiple, interacting objects. Robots Position (implicit to become explicit) Directions World Corners (implicit) Streets Avenues Beepers Walls A Robot Program – Karel First: A Robot Program – Karel First RobotDemo1 A Robot in its World: A Robot in its World Beeper Robot Wall Avenue Street Corner Origin 1st St., 1st Ave. NThe Robot World: 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 1st St and 1st Ave intersect Robots do not have to start from originObjects in the Robot World: 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 manipulateState of the Robot: State of the Robot State: those characteristics that are used to describe the current condition of the object All robots look alike The state of the robot that we are initially interested in is Positional (where is it in its world?) Street position Avenue position Direction it is facing Manipulative Beepers it may be carrying Visibility (can it be seen?) Robot Characteristics - State: Robot Characteristics - State Position A robot’s position will be defined by the corner of the World it is sitting on Direction A robot’s direction will be defined by which of the compass points it is facing in the world Number of Beepers it is carrying Visibility A Robot can be hidden from view, but it is still able to be detected by other robots Initially, we are not interested in other characteristics of robots that we might imagine We will later create other models of robots with some other characteristicsDetermining the Robot’s state: Determining the Robot’s state The robot can report its state (accessors) Report what street or avenue it is on -- street(), avenue() Report the direction it is facing -- direction() Report the number of beepers it is carrying -- beepers() Report its visibility -- isVisible() This is undocumented in Bergin’s text… But most IDE’s with context-sensitive help will show you these features Manipulation of the Robot’s state: Manipulation of the Robot’s state Only the visibility can be directly manipulated All other state is manipulated indirectly through the robots interaction and behavior in it’s World In other words, we cannot pick up a robot and place it somewhere else, it has to move to that position The only time we directly manipulate the state of the robot (other than visibility) is when we build or construct the robot Specify street, avenue, direction, and number of beepers being carried Otherwise, we indirectly manipulate state through the messages we send to a robot object A move will change street or avenue A turn will change the direction the robot is facing Beepers can be picked up or put down, changing the number of beepers the robot can carryFundamental Robot Behaviors: Fundamental Robot Behaviors 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 by being on the same corner with other robots 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 Fundamental Robot Behaviors: Fundamental Robot Behaviors 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 Fundamental Robot Methods: Fundamental Robot Methods 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 Changing Visibility -- modifiers setVisibility(boolean): We can make a robot visible or invisble by sending true or false with this message Sending a message: Sending a message To send a message we must specify the object and the behavior for that object A reference to the receiver object A period The message to be sent To send a message to a Robot named Karel: Karel.move(); reference messageLooking at a Java program: Looking at a Java program A task for two Robots TwoRobotDemo Java Programs: Java Programs Many different kinds of Java programs Primarily concerned with Applets and Applications Applets - run in the context of a web browser Applications - stand-alone programs Object-Oriented Programs solve problems with multiple, interacting objects Java programmers define objects by creating classes Generally, a Java class is written in one file, with the same name and the .java prefixThe main() method: The main() method Every Java application (not applet) has to have a main() method that is the starting point of the program IDE’s such as CodeWarrior require that the class with the main be identified Outside of an IDE, the Java application has to be started with the class that has the main methodKarel programs: Karel programs Will typically be applications The class that has the main() method will typically be called Application This Application class will be found in the file Application.javaThe Application class will: The Application class will Open the world that has the task for the robot(s) to perform In either main() Or in an anonymous, static, initializer (more on this later) Instantiate (construct) the robot(s) necessary to complete the task Send the appropriate messages to the robot(s) to perform the tasksJava Syntax Issues: Java Syntax Issues Special symbols Semi-colon ; Separates one instruction from the next Braces { } Group blocks of instructions Period . Show which instructions belong to which robot Identifiers For robot and class names Made up of characters (A..Z, a..z), digits (0..9), and underscore (_) Must start with a character Reserved words Used to structure and organize primitive instructions Comments // single line comments; /* */ multi line comments; /** */ javadoc comments Provide explanation of what is going on to other people who read our programsProgramming Errors: Programming Errors Execution Errors / Error Shutoffs Illegal move, putBeeper, or pickBeeper instructions RobotErrorsDemo 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; Java is case sensitiveProgramming Errors: 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