我知道如何将价值从一个类别转移到另一个类别。只是在这里它不起作用。我不明白为什么。
请帮我找到一个错误。
当我试图获得价值时:
c = new CartesianCoordinate(x, y);
x = c.getX();
它始终为零。
public class Velocity
{
// instance variables - replace the example below with your own
private double x;
private double y;
/**
* Constructor for objects of class Velocity
*/
public Velocity(CartesianCoordinate c)
{
// initialise instance variables
c = new CartesianCoordinate(x,y);
x = c.getX();
System.out.println(c.getX());
System.out.println(c.getY());
System.out.println(c.x);
}
public double getX()
{
return x;
}
这是我的笛卡尔坐标:
public class CartesianCoordinate
{
// instance variables - replace the example below with your own
public double x;
public double y;
/**
* Constructor for objects of class CartesianCoordinate
*/
public CartesianCoordinate(double x, double y)
{
// initialise instance variables
this.x = x;
this.y = y;
}
public void setX(double x)
{
// put your code here
this.x = x;
}
public void setY(double y)
{
this.y = y;
}
public double getX()
{
return x;
}
public double getY()
{
return y;
}
}