ボールを動かすための簡単なプログラムを作成していますが、残念ながら動きません。プログラムを実行した後に 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);
}
}