Download presentation
Presentation is loading. Please wait.
Published byLee Franklin Modified over 9 years ago
1
Georgia Institute of Technology Simulations Barb Ericson ericson@cc.gatech.edu Jan 2005
2
Georgia Institute of Technology Learning Goals Understand that object-oriented programs are simulations –of turtles –of robots –of card games –of fish
3
Georgia Institute of Technology Computers as Simulators “The computer is the Proteus of machines. Its essence is its universality, its power to simulate. Because it can take on a thousand forms and serve a thousand functions, it can appeal to a thousand tastes.” Seymour Papert in Mindstorms
4
Georgia Institute of Technology History of Turtles Seymour Papert at MIT in the 60s –By teaching the computer to do something the kids are thinking about thinking Develop problem solving skills Learn by constructing and debugging something –Learn by making mistakes and fixing them
5
Georgia Institute of Technology Using Turtles Classes created at Georgia Tech –As part of a undergraduate class Add bookClassesFinal to your classpath
6
Georgia Institute of Technology Turtle Basics The turtle starts off facing north and in the center of the world by default –World world1 = new World(); –Turtle turtle1 = new Turtle(world1); Turtles can move forward –turtle1.forward(100);
7
Georgia Institute of Technology Turning a Turtle Turtles can turn –Positive turns to right turtle1.turn(90); turtle1.forward(100); –Negative turns to the left turtle1.turn(-90); turtle1.forward(50);
8
Georgia Institute of Technology The Pen Each turtle has a pen –The default is to have the pen down to leave a trail –You can pick it up: turtle1.penUp(); turtle1.turn(-90); turtle1.forward(70); –You can put it down again: turtle1.penDown(); turtle1.forward(100);
9
Georgia Institute of Technology More Turtle Behaviors Turtles can move to a specific location –turtle1.moveTo(400,10); Of course, you can create many turtles and move them all –Run TurtleTest Creates 1000 turtles and puts them in an array of turtles. Has each turn by a random amount from 0 to 359 and go forward by 100
10
Georgia Institute of Technology Objects can Refuse Turtles won’t move completely out of the boundaries of the world –World world2 = new World(); –Turtle turtle2 = new Turtle(world2); –turtle2.forward(600);
11
Georgia Institute of Technology Objects send Messages Objects don’t “tell” each other what to do –They “ask” each other to do things Ask don’t tell Objects can refuse to do what they are asked –The object must protect it’s data Not let it get into an incorrect state
12
Georgia Institute of Technology Challenge Write a method to have a turtle draw some basic shapes –Square –Triangle –Hexagon –Circle –Spiral Use these methods to draw a simple house
13
Georgia Institute of Technology Karel J. Robot Set of classes developed to teach object- oriented programming
14
Georgia Institute of Technology Using Karel J. Robot Karel code is in karelpremeir0407 –I modified the directories to match the package name –I also modified the constructor to be public Follow the on-line book at http://csis.pace.edu/~bergin/KarelJava2ed/ch1/index.html http://csis.pace.edu/~bergin/KarelJava2ed/ch1/index.html Add KarelJRobot.jar to the classpath. You may need to add the directory karelpremeir0407 as well. Edit KarelMain.java to try things out –World.setVisible(true); // not visible to start –World.readWorld(String file) // reads the file –UrRobot karel = new UrRobot(1, 1, East, 0, Color.red); // create a robot at 1,1 facing east with 0 beepers and a red badge
15
Georgia Institute of Technology Robot Behaviors move() // moves 1 block turnLeft() // turns 90 degrees left pickBeeper() // picks up a beeper putBeeper() // drops a beeper userPause(String message) // wait for user
16
Georgia Institute of Technology World Builder
17
Georgia Institute of Technology Using the World Builder Double click on KarelJRobot.jar to bring up the world builder Use it to position walls and beepers Save it to a file Modify KarelMain to read that file
18
Georgia Institute of Technology Robot Challenges Create a maze of walls and write a method to get the robot through the maze Have the robot create a pattern by dropping beepers (like a pyramid) Have several robots work together to gather beepers
19
Georgia Institute of Technology Card Games There are public domain card images available at –http://www.waste.org/~oxymoron/files/cardshttp://www.waste.org/~oxymoron/files/cards Dr. Estell of Ohio Northern University has some card game projects at http://nifty.stanford.edu/2004/EstellCardGa me/index.html http://nifty.stanford.edu/2004/EstellCardGa me/index.html –CardAssingment.doc
20
Georgia Institute of Technology Fish Alyce Brady of Kalamazoo College –Page of resources http://max.cs.kzoo.edu/AP/MBS/index.html –Aquarium Lab Series Review of basics and set-up for Marine Biology Case Study –http://max.cs.kzoo.edu/patterns/JavaPatternLabs/Aquariu mLabSeries/index.shtmlhttp://max.cs.kzoo.edu/patterns/JavaPatternLabs/Aquariu mLabSeries/index.shtml –Minnow Project http://max.cs.kzoo.edu/AP/MBS/RelatedAssignme nts/Minnow/MinnowProj.htmlhttp://max.cs.kzoo.edu/AP/MBS/RelatedAssignme nts/Minnow/MinnowProj.html
21
Georgia Institute of Technology Summary Object-oriented programs are simulations –Consist of interacting objects who send each other messages Objects can refuse to do what you ask Objects belong to classes –An object is an instance of a class –Classes describe the data and operations that all objects of the class will have –A class creates objects Objects are responsible –They should control their data –They each have their own copy of their data
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.