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:20] – 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 38: | Line 43: | ||
lisa.turnLeft(); | lisa.turnLeft(); | ||
lisa.putBeeper(); | lisa.putBeeper(); | ||
+ | lisa.move(); | ||
+ | lisa.putBeeper(); | ||
+ | lisa.move(); | ||
+ | lisa.putBeeper(); | ||
lisa.move(); | lisa.move(); | ||
lisa.turnOff(); | lisa.turnOff(); | ||
Line 43: | Line 52: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | ====== 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.1566058822.txt.gz · Last modified: 2019/08/17 12:20 by frchris