Java中的GetX,GetY方法

时间:2018-11-08 23:31:53

标签: java methods public

当我拥有半径和alpha且无法添加除半径和alpha之外的任何其他内容时,我试图找到X和Y。

public Point (double x , double y) 
{
    _radius = Math.sqrt(Math.pow(x, 2) + Math.pow (y, 2));
    _alpha = Math.atan(y/x) * 180 / Math.PI  ;

如何找到X和Y,我想执行GetX和GetY方法

public double GetX()
{

}

谢谢。

1 个答案:

答案 0 :(得分:2)

您将必须为xy添加字段,并将值保存在构造函数中。喜欢,

private double x, y;
public Point (double x , double y) 
{
    this.x = x;
    this.y = y;
    _radius = Math.sqrt(Math.pow(x, 2) + Math.pow (y, 2));
    _alpha = Math.atan(y/x) * 180 / Math.PI  ;

然后,您可以在return x;方法中return y;getter