我正在制作一个用于移动球的简单程序,但不幸的是它没有移动,当我在运行程序后输入值 x=5 和 y=4 时,它在控制台上显示“Ball @ (0.0,0.0)”请帮助我的在哪里错误。
public class Ball
{
private double x,y; //private variables...
//creating constructors..
public void Ball(double x, double y)
{
this.x=x;
this.y=y;
}
public void Ball()
{
x=5.0;
y=4.0;
}
//getter and setter for private variables....
public double getX()
{
return x;
}
public void setX()
{
this.x=x;
}
public double getY()
{
return y;
}
public void setY()
{
this.y=y;
}
public void setXY(double x, double y)
{
this.x=x;
this.y=y;
}
public void move(double Xdisp, double Ydisp)
{
x+=Xdisp;
y+=Xdisp;
}
public String toString()
{
return "Ball @ ("+x+","+y+")";
}
public static void main(String[] args)
{
Ball b=new Ball();
System.out.println(b);
}
}