我寫了下面:有問題創造setX的(X)
public class Point
{
private double _radius , _alpha;
public Point (int x , int y)
{
//if one or more of the point values is <0 , the constructor will state a zero value.
if (x < 0)
{
x = 0;
}
if (y < 0)
{
y = 0;
}
_radius = Math.sqrt (Math.pow(x,2) + Math.pow (y,2)) ;
_alpha = Math.toDegrees(Math.atan ((double)y/x));
}
public Point (Point other) // copy constructor
{
this._radius = other._radius ;
this._alpha = other._alpha ;
}
int getX()
{
return (int) Math.round (Math.sin(_alpha)*_radius);
}
int getY()
{
return (int) Math.round (Math.cos(_alpha)*_radius);
}
void setX (int x)
{
}
}
我只是有問題寫下setX的(X),塞蒂(y)的方法,而無需創建一個新的對象...... 有人能幫我寫setX()方法嗎?
謝謝!
如果我不想定義另一種方法? – 2011-04-23 17:16:15
然後使用第一個代碼(在「或,as ...」之前)。 – ronash 2011-04-23 17:17:20
但是,如果我不能將功能添加到除_radius之外的我的課程,_alpha我會做什麼外殼? – 2011-04-23 17:24:02