your_initials_in_beepers
Your Initials in Beepers
Have a robot with a name of you choosing draw spell out your initials using beepers. Make the initials at least 5 beepers high. Here is an example if your initials happen to be DRS
:
Here is some starter code for a new class. Feel free to rename the class or the robot.
API (Application Programming Interface)
import kareltherobot.*; /** * * @author Your Name Here * @version Aug 19, 2019 * A Class with a main method to make your initials in beepers * */ public class DrawInitials implements Directions { public static void main(String[] args) { World.setDelay(30); World.setSize(8,15); World.setVisible(); task(); } public static void task() { Robot lisa = new Robot(5, 1, South, infinity); lisa.putBeeper(); 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 move()
and putBeeper()
statements it is hard to read the code. You can make a method in your class called placeSomeBeepers
:
/** * Places n beepers from Robot r ina striaght line * @param r the Robot placing the beepers * (precondtion: Robot must have enough beepers) * @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 task()
method can look like this:
public static void task() { Robot lisa = new Robot(5, 1, South, infinity); placeSomeBeepers(lisa, 4); lisa.turnLeft(); placeSomeBeepers(lisa, 3); lisa.move(); lisa.turnOff(); }
your_initials_in_beepers.txt · Last modified: 2019/08/18 12:40 by frchris