【问题标题】:my program says compiler errors after grading in gitbash我的程序在 gitbash 评分后显示编译器错误
【发布时间】:2017-03-19 11:12:06
【问题描述】:

我正在编写一个 Java 程序,在该程序中我必须让乌龟向西、向东、向北和向南移动,但到目前为止我没有让乌龟向所需的方向移动。

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

【问题讨论】:

  • 为什么你在一个名为 moveTurtleTo() 的方法中有一个 moveTurtleTo() 方法?显示你的重载方法并显示 Turtle 类
  • 编译器错误与不良行为不同。能否请您发布编译错误?
  • 请问应该怎么样?
  • FAILURE:构建失败并出现异常。 * 出了什么问题:任务 ':compileJava' 执行失败。 > 编译失败;有关详细信息,请参阅编译器错误输出。 * 尝试:使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。构建失败总时间:1.684 秒

标签: java turtle-graphics


【解决方案1】:

我猜你在钓鱼:

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

在向 SO 发帖时要清楚您的情况,您可能会更快得到更好的答案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-22
    • 2021-05-03
    • 2016-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-19
    相关资源
    最近更新 更多