your_initials_in_beepers
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| your_initials_in_beepers [2019/08/17 12:12] – frchris | your_initials_in_beepers [2019/08/18 12:40] (current) – frchris | ||
|---|---|---|---|
| Line 4: | Line 4: | ||
| {{http:// | {{http:// | ||
| - | Here is some starter code for a new class. | + | Here is some starter code for a new class. |
| + | |||
| + | |||
| + | [[http:// | ||
| + | |||
| + | <code java> | ||
| import kareltherobot.*; | import kareltherobot.*; | ||
| /** | /** | ||
| Line 13: | Line 18: | ||
| | | ||
| */ | */ | ||
| - | + | public class DrawInitials implements Directions | |
| - | public class DrawInitials implements Directions { | + | { |
| - | + | public static void main(String[] args) | |
| - | public static void main(String[] args) { | + | { |
| - | World.setDelay(50); | + | World.setDelay(30); |
| - | World.setSize(8, | + | World.setSize(8, |
| World.setVisible(); | World.setVisible(); | ||
| task(); | task(); | ||
| } | } | ||
| - | | + | |
| - | + | public static void task() | |
| - | | + | { |
| - | + | ||
| - | | + | Robot |
| - | | + | |
| - | | + | lisa.putBeeper(); |
| - | lisa.turnOff(); | + | lisa.move(); |
| - | } | + | lisa.putBeeper(); |
| + | lisa.move(); | ||
| + | lisa.putBeeper(); | ||
| + | lisa.move(); | ||
| + | lisa.putBeeper(); | ||
| + | lisa.move(); | ||
| + | lisa.turnLeft(); | ||
| + | lisa.putBeeper(); | ||
| + | lisa.move(); | ||
| + | lisa.putBeeper(); | ||
| + | lisa.move(); | ||
| + | lisa.putBeeper(); | ||
| + | lisa.move(); | ||
| + | lisa.turnOff(); | ||
| + | } | ||
| } | } | ||
| </ | </ | ||
| + | ====== Making a method ====== | ||
| + | With all those '' | ||
| + | * Places n beepers from Robot r ina striaght line | ||
| + | * @param r the Robot placing the beepers | ||
| + | * (precondtion: | ||
| + | * @param n the number of beepers to place | ||
| + | */ | ||
| + | public static void placeSomeBeepers(Robot r, int n) | ||
| + | { | ||
| + | for (int i=0; i < n; i++) | ||
| + | { | ||
| + | r.putBeeper(); | ||
| + | r.move(); | ||
| + | } | ||
| + | }</ | ||
| + | |||
| + | Now all your '' | ||
| + | { | ||
| + | |||
| + | Robot lisa = new Robot(5, 1, South, infinity); | ||
| + | |||
| + | placeSomeBeepers(lisa, | ||
| + | lisa.turnLeft(); | ||
| + | placeSomeBeepers(lisa, | ||
| + | lisa.move(); | ||
| + | lisa.turnOff(); | ||
| + | }</ | ||
your_initials_in_beepers.1566058363.txt.gz · Last modified: 2019/08/17 12:12 by frchris