Advertisement
Guest User

HomeTask1

a guest
Sep 17th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.57 KB | None | 0 0
  1. import stanford.karel.*;
  2.  
  3. public class HW2First extends SuperKarel{
  4.    
  5.     private void toNewspaper(){
  6.        
  7.         while(frontIsClear()){
  8.             move();
  9.         }
  10.         turnRight();
  11.        
  12.         while(leftIsBlocked()){
  13.             move();
  14.             }
  15.         turnLeft();
  16.         move();
  17.     }
  18.    
  19.     private void pickNewspaper(){
  20.         pickBeeper();
  21.     }
  22.    
  23.     private void backToHome(){
  24.         turnAround();
  25.        
  26.         while(frontIsClear()){
  27.             move();
  28.         }
  29.         turnRight();
  30.        
  31.         while(frontIsClear()){
  32.             move();
  33.         }
  34.         turnRight();
  35.     }
  36.    
  37.    
  38.    
  39.     public void run(){
  40.         toNewspaper();
  41.         pickNewspaper();
  42.         backToHome();
  43.        
  44.        
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement