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:11] – 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. |
- | import kareltherobot.World; | + | |
+ | |||
+ | [[http:// | ||
+ | |||
+ | <code java> | ||
+ | import kareltherobot.*; | ||
/** | /** | ||
| | ||
- | * @author | + | * @author |
* @version Aug 19, 2019 | * @version Aug 19, 2019 | ||
| | ||
| | ||
*/ | */ | ||
- | + | 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.1566058283.txt.gz · Last modified: 2019/08/17 12:11 by frchris