2017-03-19 3 views
-1

私はカメに西、東、北と南を動かす必要があるJavaプログラムを書いていますが、これまでにカメが移動することはありません所望の方向に移動する。gitbashでグレーディングした後のコンパイラエラー

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) 
    { 

    } 

    // TODO - you need to implement this. Move the given turtle to the East, n times 
    public static void moveTurtleEast(Turtle t, int n) 
    { 
     for(int i=0; i <n;i++){ 
     t.moveEast(); 
    } 

    // TODO - you need to implement this. Move the given turtle to the North, n times 
    public static void moveTurtleNorth(Turtle t, int n) 
    { 
     for(int i=0; i <n;i++){ 
     t.moveNorth(); 
    } 

    // TODO - you need to implement this. Move the given turtle to the South, n times 
    public static void moveTurtleSouth(Turtle t, int n) 
    { 
     for(int i=0; i <n;i++){ 
     t.moveSouth(); 
    } 

    // 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) 
    { 
     moveTurtleTo(turtle.xPos,turtle.yPos); 
    } 

    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); 
    } 
} 
+0

moveTurtleTo()という名前のメソッド内にmoveTurtleTo()メソッドがあるのはなぜですか?オーバーロードされたメソッドを表示して、Turtleクラスを表示してください – abcOfJavaAndCPP

+0

コンパイラのエラーは望ましくない動作とは異なります。コンパイルエラーを投稿してください。 – efekctive

+0

どうしたらいいですか? – oneirion

答えて

0

私はあなたのようなもののために釣りをしている推測している:SOに投稿すると、あなたはおそらくより速く、より良い答えを得るでしょうとき

public class Assignment7 { 

    public static void moveTurtleWest(Turtle t, int n) 
    { 
     for (int i = 0; i < n; i++) { 
      t.moveWest(); 
     } 
    } 

    public static void moveTurtleEast(Turtle t, int n) 
    { 
     for (int i = 0; i < n; i++) { 
      t.moveEast(); 
     } 
    } 

    public static void moveTurtleNorth(Turtle t, int n) 
    { 
     for (int i = 0; i < n; i++) { 
      t.moveNorth(); 
     } 
    } 

    public static void moveTurtleSouth(Turtle t, int n) 
    { 
     for (int i = 0; i < n; i++) { 
      t.moveSouth(); 
     } 
    } 

    public static void moveTurtleTo(Turtle t, int x, int y) 
    { 
     int delta_x = x - turtle.xPos; 
     int delta_y = y - turtle.yPos; 

     if (delta_x > 0) { 
      moveTurtleEast(t, delta_x); 
     } else if (delta_x < 0) { 
      moveTurtleWest(t, -delta_x); 
     } 

     if (delta_y > 0) { 
      moveTurtleNorth(t, delta_x); 
     } else if (delta_y < 0) { 
      moveTurtleSouth(t, -delta_x); 
     } 
    } 

    public static void main(String[] args) { 

     Turtle t = new Turtle(); 

     moveTurtleTo(t, 15, 16); 
    } 
} 

は、あなたの状況について明確なこと。

関連する問題