Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import kareltherobot.*;
- import java.awt.Color;
- /**
- * Write a concise summary of class HarvestAdvanced here.
- *
- * @author Jason Yang
- *
- * @version 2/11/2017
- */
- public class HarvestAdvanced extends Robot
- {
- /**
- * Creates a HarvestAdvanced object.
- *
- * @param street specifies the vertical position on the grid
- * of this robot.
- * @param avenue specifies the horizontal position on the grid
- * of this robot.
- * @param direction specifies the direction of this robot.
- * @param beepers specifies this robot's number of beepers.
- */
- public HarvestAdvanced (int street, int avenue,
- Direction direction, int beepers)
- {
- super(street, avenue, direction, beepers);
- }
- /* HarvestAdvanced methods: */
- public void turnRight(){
- turnLeft();
- turnLeft();
- turnLeft();
- }
- public void harvestRow(){
- checkBeeper();
- move();
- checkBeeper();
- move();
- checkBeeper();
- move();
- checkBeeper();
- move();
- checkBeeper();
- }
- public void checkBeeper(){
- if (!nextToABeeper()) {
- putBeeper();
- }
- else {
- pickBeeper();
- if (nextToABeeper()) {
- pickBeeper();
- }
- putBeeper();
- }
- }
- public void transitionRight(){
- turnLeft();
- move();
- turnLeft();
- }
- public void transitionLeft(){
- turnRight();
- move();
- turnRight();
- }
- public void run(){
- move();
- harvestRow();
- transitionRight();
- harvestRow();
- transitionLeft();
- harvestRow();
- transitionRight();
- harvestRow();
- transitionLeft();
- harvestRow();
- transitionRight();
- harvestRow();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement