【问题标题】:Distance formula距离公式
【发布时间】:2015-09-24 00:03:37
【问题描述】:

我需要实验室方面的帮助。我的老师没有告诉我们任何事情,他告诉我们要弄清楚。所以我可以使用我能得到的任何帮助。谢谢你

第 1 步:第一步是否一切都好,包括我的距离公式,我正在尝试设置 xx 等于 xyy 等于 y 所以我没有线索如何做到这一点,你能帮我吗?

    class Point {
        private int x;
        private int y;

        public Point()                          // (0, 0)
        {
          x = 0;
          y = 0;
    }

        public Point(int xx, int yy)
        {  
           xx = x;
           yy = y;
    }

        public int getX()                       // return field values
        {
            return x;
    }
        public int getY()
        {
            return y;

    }

        // Use the distance formula to find the distance of this point from the origin (0,0)
        public double distanceFromOrigin()
        {
                int d = 0;


                d = Math.squrt(Math.pow(xx - x) + (Math.pow(yy - y);
}

我的距离公式是否正确,如果不是什么问题,你能帮我解决它吗?

第二步:我需要找到曼哈顿距离

// Find the "manhattan" distance between current point and other.
//  You can look at http://x...content-available-to-author-only...t.gov/dads//HTML/manhattanDistance.html for help
public double distance(Point other) 
{/*write the code for here*/}

我真的不知道如何做第 2 步,所以我真的可以使用很多帮助,非常感谢你们

第 3 步:在我找到当前点与其他点之间的曼哈顿距离之后。我需要将其更改为新值,我不知道如何获取新值以及如何更改它。之后,我需要通过翻译 T 来转移点,我不知道该怎么做,所以我需要帮助

// Changes the coordinate to new values
public void setLocation(int x, int y)
{/*write the code for here*/}

//Shift the point by the translation T<x+h,y+k>
public void translate(int h, int k)
{/*write the code for here*/}

顺便说一句,伙计们,我只是在基础计算机科学,所以我不能使用所有花哨的东西,所以保持基本和简单

【问题讨论】:

  • 这看起来像 Java,而不是 JavaScript
  • 另外,为什么要从 step2 中删除此链接? xlinux.nist.gov/dads/HTML/manhattanDistance.html
  • d = Math.squrt(Math.pow(xx - x) + (Math.pow(yy - y); 应该是 d = Math.sqrt(Math.pow(xx - x) + (Math.pow(yy - y)); 即 sqrt 不是 squrt 和结束括号。顺便说一句,这是 JavaScript 论坛而不是 JAVA。
  • @Blindman67 这不是 JavaScript 论坛......
  • 上课?输入double? Public?这是什么,Java?

标签: java formula distance


【解决方案1】:

就像 torvin 在 cmets 中所说的那样,它看起来真的像 Java 而不是 Javascript。尽管名称相似,但它们是两种不同的语言。

一般看你的代码,有明显的错误,不知道你用什么IDE(集成开发环境)写代码。帮助您编写代码的适当程序会发现这些。

就在你的 distanceFromOrigin() 中,你错过了:

  • 2 个右括号
  • Math.squrt() 应该是 Math.sqrt()
  • 您没有返回值,尽管已将方法返回类型设置为双精度

老实说,您可能应该先设置一个 IDE 并完成一个基本的 Java 教程,然后再继续。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多