User Tools

Site Tools


your_initials_in_beepers

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
your_initials_in_beepers [2019/08/17 12:29] frchrisyour_initials_in_beepers [2019/08/18 12:40] (current) frchris
Line 4: Line 4:
 {{http://danshuster.com/apcs/karel25.jpg|}} {{http://danshuster.com/apcs/karel25.jpg|}}
  
-Here is some starter code for a new class.  Feel free to rename the class or the robot.<code java>+Here is some starter code for a new class.  Feel free to rename the class or the robot. 
 + 
 + 
 +[[http://csis.pace.edu/%7Ebergin/KarelJava2ed/KJRdocs/index.html|API]] (Application Programming Interface) 
 + 
 +<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 45: Line 54:
  
 ====== Making a method ====== ====== Making a method ======
-With all those ''move()'' and ''putBeeper()'' statements it is hard to read the code.  You can add a method called ''placeSomeBeepers'':<code java>/**+With all those ''move()'' and ''putBeeper()'' statements it is hard to read the code.  You can make  a method in your class called ''placeSomeBeepers'':<code java>/**
  * Places n beepers from Robot r ina striaght line  * Places n beepers from Robot r ina striaght line
  * @param r the Robot placing the beepers   * @param r the Robot placing the beepers 
Line 60: Line 69:
  }</code>  }</code>
  
 +Now all your ''task()'' method can look like this:<code java>public static void task()
 + {
  
 + Robot lisa = new Robot(5, 1, South, infinity);
 +
 + placeSomeBeepers(lisa, 4);
 + lisa.turnLeft();
 + placeSomeBeepers(lisa, 3);
 + lisa.move();
 + lisa.turnOff();
 + }</code>
your_initials_in_beepers.1566059397.txt.gz · Last modified: 2019/08/17 12:29 by frchris

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki