嗨im新的java我不確定如何在java中使用類功能。我的老師給了我們point2d類,並希望我們在那裏使用這個函數。有一個函數調用distanceTo如何在java中使用不同的類功能
// return Euclidean distance between this point and that point
public double distanceTo(final Point2D that) {
final double dx = this.x - that.x;
final double dy = this.y - that.y;
return Math.sqrt(dx*dx + dy*dy);
}
我不知道我是如何實現這一點。這是我的代碼
public static int calc(int amount)
{
for (int t = 0; t < amount; t++)
{
double current = 0;
double x = StdRandom.random();
double y = StdRandom.random();
Point2D p = new Point2D(x, y);
if (current < distanceTo(Point2D p))
{
}
我試圖用distanceTo(p)
和distanceTo(Poin2D)
並沒有什麼作品。
在此先感謝
如果該功能是由靜態的,它需要兩個參數。 – michaelb958 2013-04-18 04:54:38