MD 5th Java Using RobotsI

Uploaded from authorPOINTLite
Views:
 
Category: Entertainment
     
 

Presentation Description

No description available.

Comments

By: khalidmehz (20 month(s) ago)

Dear Author, Please send me a copy of this presentation. its really helpful for me. Thanks in anticipation...

Presentation Transcript

Introduction to Java using Robots: 

Introduction to Java using Robots ACSE 2004 Presentation Michael Devoy, Monsignor Doyle C.S.S., Cambridge mdevoy@look.ca

Objectives: 

Objectives Understand the world of Karel the Robot Understand how Karel the Robot can be used to teach object oriented programming in Java write simple programs to instruct a Robot to accomplish a task that involve: creating a Java application instantiating objects, including Robots invoking methods of a Robot

Why Use Robots: 

Why Use Robots Fun Visual Early introduction to Object Oriented concepts Teach important concepts without getting stuck in too much Java syntax Students start by using objects before needing to learn how to build classes Teachers don’t have to build their own classes for students to use Availability of resources, both free and purchasable

The World of Robots: 

The World of Robots Robots ‘live’ in a City A City is displayed in a CityFrame A City has intersections of streets and avenues Things may be on an intersection Robots may pick up or put down Things Walls may be next to an intersection Robots can not walk through Walls (they break)

The World of Robots UML: 

The World of Robots UML Wall Thing

A Typical Robot Problem: 

A Typical Robot Problem The teacher designs the city layout and poses the problem The student writes a program that instructs a robot (or robots) to complete the task For example: walk around the square and pick up all Things

Getting Started: 

Getting Started An environment to create Java programs in: Holt’s Ready to Program OR Sun’s SDK Any editor (such as notepad or text pad) or IDE (such as BlueJ or JBuilder) JAR file containing the required Robot classes, available free at http://www.math.uwaterloo.ca/~bwbecker/robots/

Configuring Ready: 

Configuring Ready Adding becker.jar so Ready has access to the package

Java Background: 

Java Background Java was created by Sun Microsystems and is free (http://java.sun.com/) The SDK (system developer’s kit) is used to compile and run Java applications and applets A Java program is composed of a number of classes you write, that work together Most programmers use an IDE, such as Ready Source File (MyClass.java) Java Compiler Byte Code File (MyClass.class) JVM

Pattern for a Java Application: 

Pattern for a Java Application import <<importedPackage>>; public class <<ClassName>> extends Object { public static void main(String[] args) { << list of statements to be executed>>; } } For Example: import becker.robots.*; public class HarvestAroundSquare extends Object { public static void main(String[] args) { } }

Pattern for Instantiating an Object: 

Pattern for Instantiating an Object <<variableType>> <<objectName>>; <<objectName>> = new <<ClassName>>(<<parameters>>); runs the constructor method to assign values to object variables and assign a value to the reference Or, on one line: <<variableType>> <<objectName>> = new <<ClassName>>(<<parameters>>); For Example: Robot karel; karel = new Robot (waterloo, 1, 5, Directions.EAST, 0); Or Robot karel = new Robot (waterloo, 1, 5, Directions.EAST, 0);

Pattern for Calling an Object’s Method: 

Pattern for Calling an Object’s Method <<objectName>>.<<methodName>>(<<parameters>>); Dot between object and method Method always followed by ( ), which may or may not contain parameters For Example: karel.move(); Other methods a Robot can perform include: turnLeft(), pickThing(), putThing(), frontIsClear() http://www.math.uwaterloo.ca/~bwbecker/robots/doc/becker/robots/Robot.html

Putting the Patterns Together: 

Putting the Patterns Together import becker.robots.*; public class HarvestAroundSquare extends Object { public static void main (String[] args) { City waterloo = new City ("HarvestAroundSquare.txt"); CityFrame frame = new CityFrame (waterloo); Robot karel = new Robot (waterloo, 1, 5, Directions.EAST, 0); int side = 0; while (side < 4) { while (karel.frontIsClear ()) { karel.move (); karel.pickThing (); } //end while karel.turnLeft (); side++; } //end while } //end main } //end class

Hands on Application Modification: 

Hands on Application Modification Start Ready to Program open HarvestAroundSquare.java predict what the program will do run the program to verify your prediction identify the logic error modify the program to correct the logic error run your modification to ensure it is correct open HarvestAroundSquare4.java, to see how a team of robots can work together

Hands on Application Creation: 

Hands on Application Creation Use HarvestAroundSquare.java as a resource Use the file relayCity.txt to setup Walls and Things set the number of streets and avenues in the CityFrame using parameters in the constructor, such as: CityFrame frame = new CityFrame(waterloo, 20, 10);

Hands on Application Creation: 

Hands on Application Creation Make the first robot pick up all the Things on the stairs and then drop them on the corner where the second robot is standing Make the second robot pick up all the Things and distribute them on its stairs

Resources: 

Resources Becker Robots (Documentation & Downloads) http://www.math.uwaterloo.ca/~bwbecker/robots/ Introductory Course using Robots for Students http://csis.pace.edu/~bergin/KarelJava2ed/Karel++JavaEdition.html Sun Java Class Documentation http://java.sun.com/j2se/1.4.2/docs/api/index.html Sun Java Tutorials http://developer.java.sun.com/developer/onlineTraining/