Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Sep 25th, 2012  |  syntax: None  |  size: 1.74 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /*Susan Tang
  2.  *Schull - CS 111
  3.  *Username: Stang
  4.  *Pset 3
  5.  *Task 1
  6.  *Due: Sept. 24, 2012
  7.  */
  8.  
  9. public class Follower extends TickBuggle {
  10.  
  11.   public void tick(){
  12.  
  13.     if(atEnd()){
  14.      
  15.       return;
  16.      
  17.     }
  18.    
  19.   }
  20.  
  21.   //moves Buggle forward and picks up bagel; also picks up any existing bagels under it
  22.   public void followBagel(){
  23.    
  24.     brushDown();
  25.    
  26.     if(isOverBagel()){
  27.      
  28.       pickUpBagel();
  29.        
  30.     } else {
  31.    
  32.       forward();
  33.       pickUpBagel();
  34.    
  35.    }
  36.   }
  37.    
  38.   //looks for a Bagel directly in front of the Buggle
  39.   public boolean isBagelPresent(){
  40.    
  41.       if(isFacingWall()){
  42.         return false;
  43.        
  44.       } else {
  45.        
  46.       brushUp();
  47.       forward();
  48.       boolean bagelPresence = isOverBagel();
  49.       backward();
  50.       brushDown();
  51.       return bagelPresence;
  52.        
  53.     }  
  54.    }
  55.  
  56.   //looks for a Bagel to the left of the Buggle
  57.   public boolean leftBagelPresent(){
  58.    
  59.        left();
  60.        return isBagelPresent();
  61.    
  62.   }
  63.  
  64.   //lookts for a Bagel to the right of the Buggle
  65.   public boolean rightBagelPresent() {
  66.    
  67.        right();
  68.        right();
  69.        return isBagelPresent();
  70.          
  71.        }
  72.  
  73.   //Searches for the end of the path; if not at the end, the Buggle continues along the Bagel path.
  74.   public boolean atEnd() {
  75.    
  76.     boolean endVar = false;
  77.     if(isOverBagel()){
  78.       pickUpBagel();
  79.       } else if (isBagelPresent()) {
  80.         followBagel();
  81.       } else if (leftBagelPresent()){
  82.         followBagel();
  83.       } else if (rightBagelPresent()){
  84.         followBagel();
  85.       } else {endVar = true;
  86.             return endVar;}
  87.    
  88.     return endVar;
  89.      
  90.     }  
  91.   }