新手,代码总是出错,调试很多次都不行,想知道怎么改的
class Point2D{int x , y ;
double s;
Point2D(int a ,int b)
{
x=a;
y=b;
}
void offset(int a,int b)
{
x=x+a;
y=y+b;
}
double distance(Point2D p1,Point2D p2)
{
double m;
m = Math.sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
return m;
}
}
public class Point3D extends Point2D{
int z;
public Point3D(int a,int b ,int c)
{
super(x ,y);
z=c;
}
void offset(int a,int b,int c)
{ x=x+a;
y=y+b;
z=z+c;
}
double distance(Point3D p1,Point3D p2)
{
double m;
m = Math.sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)+(p1.z-p2.z)*(p1.z-p2.z));
return m;
}
public static void main(String args[]){
Point2D p2d1= new Point2D(2,3);
Point2D p2d2= new Point2D(4,5);
Point3D p3d1= new Point3D(2,2,2);
Point3D p3d2= new Point3D(3,3,3);
System.out.println(new Point2D().distance(p2d1,p2d2));
System.out.println(new Point3D().distance(p3d1,p3d2));
}
}
总是出错,怎么回事啊