title: Java Programming: Turtle not moving in desired direction
body: <p>I'm writing a Java program in which I have to get the turtle to move West, but what I have so far isn't getting the turtle to move in the desired direction.</p>
  
  <pre><code>public static void moveTurtleWest(Turtle t, int n)
      {
          for(; n &gt; t.getX();n-- ){
              t.moveWest();
              }
      }
  </code></pre>
  
  <p>Here is the rest of my code:</p>
  
  <pre><code>package assignment;
  
  import java.text.MessageFormat;
  import java.util.Scanner;
  
  import java.awt.Point;
  import java.awt.Dimension;
  import java.awt.Rectangle;
  
  import java.time.LocalDate;
  
  /**
   * This class represents a turtle, like a Logo-like turtle, which keeps its position.
   * The turtle keeps its x and y position, and has methods moveNorth() etc which change it
   * Assume normal math coordinates and map convention, so as you move up (North) y increases, and as you move East x increases.
   *
   */
  class Turtle {
  
      // HINT - you may want to have variables to keep the position. Keep these variables private,
      private int x,y;
  
      // TODO - The empty constructor initializes position to 10,10
      public Turtle() {
          this.x = 10;
          this.y = 10;
      }
  
      public int getX() { 
          // TODO - implement this
          return this.x;
      }
      public int getY() {
          // TODO - implement this
          return this.y;
      }
  
      public void moveNorth() {
          // TODO - implement this. this increments the y coordinate by one unit
          this.y += 1;
      }
  
      public void moveSouth() {
          // TODO - implement this. this decrements the y coordinate by one unit
          this.y -=1;
      }
  
      public void moveEast() {
          // TODO - this increments the x coordinate by one unit
          this.x +=1;
      }
  
      public void moveWest() {
          // TODO - this decrements the x coordinate by one unit
          this.x -=1;
      }
  
      public String toString() {
          return "Turtle[x="+getX()+", y="+getY()+"]";
      }
  
      public boolean equals(Turtle t)
      {
          // TODO - you need to implement this
          // two turtles are equal if their X and Y coordinates are equal.
          if (t == null) {
              return false;
          }
          if (!(t instanceof Turtle)) {
              return false;
          }
          return (x == ((Turtle) t).x &amp;&amp; y == ((Turtle) t).y);
      }
  
      public void move(String direction)
      {
          // TODO - you need to implement this
          // move to the right direction; direction can be North, South, East, West
          moveEast();
      }
  }
  
  public class Assignment7 {
      // TODO - you need to implement this. Move the given turtle to the West, n times
      public static void moveTurtleWest(Turtle t, int n)
      {
          for(; n &gt; t.getY();n-- ){
              t.moveWest();
              }
      }
  
      // TODO - you need to implement this. Move the given turtle to the East, n times
      public static void moveTurtleEast(Turtle t, int n)
      {
      }
  
      // TODO - you need to implement this. Move the given turtle to the North, n times
      public static void moveTurtleNorth(Turtle t, int n)
      {
      }
  
      // TODO - you need to implement this. Move the given turtle to the South, n times
      public static void moveTurtleSouth(Turtle t, int n)
      {
      }
  
      // TODO - you need to implement this. Move the turtle to the asked position, by calling MoveXXX etc
      public static void moveTurtleTo(Turtle t, int x, int y)
      {
  
      }
      public static void main(String[] args) {
          // you can use this as you wish to test or exercise your function. Not graded.
          Turtle t=new Turtle();
          moveTurtleTo(t,15,16);
          System.out.println(t);  
      }
  }
  </code></pre>
  
  <p>Here is the code that is executing when I run this method in git Bash:</p>
  
  <pre><code>public void testMoveWest()
      {
          Turtle t=new Turtle();
          t.moveWest();
          t.moveWest();
          t.moveWest();
          t.moveWest();
  
          Assert.assertEquals(6,  t.getX());
      }
  
      @Grade(points=10)
      @Test
  </code></pre>
  
  <p>Any help is appreciated and points will be rewarded.
  Thanks in advance!</p>