Total Pageviews

Tuesday, March 20, 2012

SKILL BUILDER DEFINING METHODS

/**
 * Extends the functions of the original <code>Turtle</code> class.
 *
 * @author Your name
 * @version  1.0.0
 */
public class ExtendedTurtle extends Turtle {

    /**
     * Paints its current location and moves to the front location.
     *
     * @param colorName  a string that specifies the color name.
     */
    public void paintAndMove(String  colorName) {
   
        paint(colorName);
        move();
    }

    /**
     * Turns the turtle to the opposite direction.
     */
    public void turn180()
{

turnLeft();
turnLeft();
   
       
    }

    /**
     * Paints and moves four locations.
     *
     * @param colorName  a string that specifies the color name.
     */
    public void paintAndMove4(String  colorName) {

paintAndMove(colorName);
paintAndMove(colorName);
paintAndMove(colorName);
paintAndMove(colorName);
       
    }

    /**
     * Paints a 2 x 2 square and returns to its original position.
     *
     * @param colorName  a string that specifies the color name.
     */
    public void paintSmallSquare(String  colorName) {

    paintAndMove(colorName);
turnRight();
paintAndMove(colorName);
turnRight();
paintAndMove(colorName);
turnRight();
paintAndMove(colorName);
turnRight();
   
       
       
    }

    /**
     * Paints a 4 x 4 square and returns to its original position.
     *
     * @param colorName  a string that specifies the color name.
     */
    public void paintLargeSquare(String  colorName) {


      paintAndMove(colorName);
          paintAndMove(colorName);
          paintAndMove(colorName);
          turnRight();

          paintAndMove(colorName);
          paintAndMove(colorName);
          paintAndMove(colorName);
          turnRight();
         
          paintAndMove(colorName);
          paintAndMove(colorName);
          paintAndMove(colorName);
          turnRight();

          paintAndMove(colorName);
          paintAndMove(colorName);
          paintAndMove(colorName);
          turnRight();
move();
turnRight();
paintAndMove(colorName);
          paintAndMove(colorName);
          paintAndMove(colorName);

  turnLeft();
   turnLeft();
move();
   paintAndMove(colorName);
          paintAndMove(colorName);
 
     turnRight();
move();
turnRight();
paintAndMove(colorName);
paintAndMove(colorName);
paintAndMove(colorName);
    }
}

No comments:

Post a Comment