Download presentation
Presentation is loading. Please wait.
Published byClarissa Daniels Modified over 9 years ago
1
Lab 1 City, Robot, Thing, Wall
2
Documentation of Classes and Methods
3
City Class Constructs a city that the robot will move in it. City newYork = new City();
4
Robot Class Constructs a Robot to move in the city. Robot hal = new Robot(newYork, 1, 2, Direction.SOUTH);
5
Thing Class Constructs a thing that can be put in a city. Thing t1 = new Thing(newYork, 2, 2);
6
Wall Class Constructs walls in the city to block robots. Wall wa = new Wall(newYork, 3, 3, Direction.WEST);
7
Methods in Robot Class www.learningwithrobots.com/doc/becker/robots/Robot.html
8
Methods in Thing Class http://www.learningwithrobots.com/doc/becker/robots/Thing.html
9
Classes in becker Library http://www.learningwithrobots.com/doc/becker/robots/package-summary.html
10
Example 1 package rob; import becker.robots.*; public class Rob extends Object { public static void main(String[] args) { // Declare the objects needed City newYork = new City(); Robot hal = new Robot(newYork, 1, 2, Direction.SOUTH); Thing t1 = new Thing(newYork, 2, 2); Wall wa = new Wall(newYork, 3, 3, Direction.WEST); Thing t2 = new Thing(newYork, 3, 2); Thing t3 = new Thing(newYork, 4, 2); hal.move(); hal.pickThing(); hal.move(); hal.pickThing(); hal.move(); hal.pickThing(); hal.move(); hal.putThing(); hal.move(); }
11
Example 2 package rob; import becker.robots.*; import becker.robots.icons.*; import java.awt.Color; public class Lamp extends Thing {public Lamp(City aCity, int aStreet, int anAvenue) {super(aCity, aStreet, anAvenue); this.turnOn(); } public void turnOn() { Color onColor = new Color(255, 255, 200); CircleIcon onIcon = new CircleIcon(onColor); onIcon.setSize(0.75); this.setIcon(onIcon); } public void turnOff() { Color offColor = new Color(0, 0, 0); CircleIcon offIcon = new CircleIcon(offColor); this.setIcon(offIcon); }
12
Cont.. Example 2 package rob; import becker.robots.*; public class Main { public static void main(String[] args) { // Construct the initial situation. City paris = new City(); Lamp lamp1 = new Lamp(paris, 1, 1); Robot lampMover = new Robot(paris, 1, 0, Direction.EAST); // Use the robot to move one of the lamps. lampMover.move(); lampMover.pickThing(); lampMover.move(); lampMover.putThing(); lampMover.move(); lamp1.turnOff(); }
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.