Advertisement
yangjason69

HarvestAdvanced

Mar 26th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.96 KB | None | 0 0
  1.  
  2. import kareltherobot.*;
  3. import java.awt.Color;
  4.  
  5. /**
  6.  * Write a concise summary of class HarvestAdvanced here.
  7.  *
  8.  * @author  Jason Yang
  9.  *
  10.  * @version 2/11/2017
  11.  */
  12. public class HarvestAdvanced extends Robot
  13. {
  14.     /**
  15.      * Creates a HarvestAdvanced object.
  16.      *
  17.      * @param street     specifies the vertical position on the grid
  18.      *                   of this robot.
  19.      * @param avenue     specifies the horizontal position on the grid
  20.      *                   of this robot.
  21.      * @param direction  specifies the direction of this robot.
  22.      * @param beepers    specifies this robot's number of beepers.
  23.      */
  24.     public HarvestAdvanced (int street, int avenue,
  25.            Direction direction, int beepers)
  26.     {
  27.         super(street, avenue, direction, beepers);
  28.     }
  29.     /* HarvestAdvanced methods: */
  30.     public void turnRight(){
  31.         turnLeft();
  32.         turnLeft();
  33.         turnLeft();
  34.     }
  35.     public void harvestRow(){
  36.         checkBeeper();
  37.         move();
  38.         checkBeeper();
  39.         move();
  40.         checkBeeper();
  41.         move();
  42.         checkBeeper();
  43.         move();
  44.         checkBeeper();
  45.     }
  46.    
  47.     public void checkBeeper(){
  48.         if (!nextToABeeper()) {
  49.             putBeeper();
  50.         }
  51.         else {
  52.             pickBeeper();
  53.             if (nextToABeeper()) {
  54.                 pickBeeper();
  55.             }
  56.             putBeeper();
  57.         }
  58.     }
  59.    
  60.     public void transitionRight(){
  61.         turnLeft();
  62.         move();
  63.         turnLeft();
  64.     }
  65.    
  66.     public void transitionLeft(){
  67.         turnRight();
  68.         move();
  69.         turnRight();
  70.     }
  71.    
  72.     public void run(){
  73.         move();
  74.         harvestRow();
  75.         transitionRight();
  76.         harvestRow();
  77.         transitionLeft();
  78.         harvestRow();
  79.         transitionRight();
  80.         harvestRow();
  81.         transitionLeft();
  82.         harvestRow();
  83.         transitionRight();
  84.         harvestRow();
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement