这个java程序有个错误,是找不到符号,求大神赐教!!
classPoint2D{intx,y;Point2D(){x=0;y=0;}Point2D(inta,intb){x=a;y=b;}voidoffset(inta,in...
class Point2D{
int x,y;
Point2D(){x=0;y=0;}
Point2D(int a,int b){x=a;y=b;}
void offset(int a,int b){x+=a;y+=b;}
public double diatance(Point2D P1,Point2D P2){
double dis;
return dis=Math.sqrt(Math.pow(P1.x-P2.x,2)+Math.pow(P1.y-P2.y,2));
}
}
class Point3D extends Point2D{
int x,y,z;
Point3D(){x=0;y=0;z=0;}
Point3D(int a,int b,int c){x=a;y=b;z=c;}
Point3D(Point2D P,int c){x=P.x;y=P.y;z=c;}
void offset(int a,int b,int c){x+=a;y+=b;z+=c;}
public double distance(Point3D P1,Point3D P2){
double dis;
return dis=Math.sqrt(Math.pow(P1.x-P2.x,2)+Math.pow(P1.y-P2.y,2)+Math.pow(P1.z-P2.z,2));
}
}
public class subject_1_1{
public static void main(String args[]){
Point2D d2=new Point2D();
Point3D d3=new Point3D();
Point2D p2d1=new Point2D(2,4);
Point2D p2d2=new Point2D(5,12);
Point3D p3d1=new Point3D(3,7,8);
Point3D p3d2=new Point3D(5,1,6);
System.out.println("p2d1和p2d2之间的距离为"+d2.distance(p2d1,p2d2));
System.out.println("p3d1和p3d2之间的距离为"+d3.distance(p3d1,p3d2));
}
} 展开
int x,y;
Point2D(){x=0;y=0;}
Point2D(int a,int b){x=a;y=b;}
void offset(int a,int b){x+=a;y+=b;}
public double diatance(Point2D P1,Point2D P2){
double dis;
return dis=Math.sqrt(Math.pow(P1.x-P2.x,2)+Math.pow(P1.y-P2.y,2));
}
}
class Point3D extends Point2D{
int x,y,z;
Point3D(){x=0;y=0;z=0;}
Point3D(int a,int b,int c){x=a;y=b;z=c;}
Point3D(Point2D P,int c){x=P.x;y=P.y;z=c;}
void offset(int a,int b,int c){x+=a;y+=b;z+=c;}
public double distance(Point3D P1,Point3D P2){
double dis;
return dis=Math.sqrt(Math.pow(P1.x-P2.x,2)+Math.pow(P1.y-P2.y,2)+Math.pow(P1.z-P2.z,2));
}
}
public class subject_1_1{
public static void main(String args[]){
Point2D d2=new Point2D();
Point3D d3=new Point3D();
Point2D p2d1=new Point2D(2,4);
Point2D p2d2=new Point2D(5,12);
Point3D p3d1=new Point3D(3,7,8);
Point3D p3d2=new Point3D(5,1,6);
System.out.println("p2d1和p2d2之间的距离为"+d2.distance(p2d1,p2d2));
System.out.println("p3d1和p3d2之间的距离为"+d3.distance(p3d1,p3d2));
}
} 展开
3个回答
展开全部
拼写错误。
这个distance应该加上static成为一个类工具方法。
这个distance应该加上static成为一个类工具方法。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
System.out.println("p2d1和p2d2之间的距离为"+d2.distance(p2d1,p2d2));
这个里面报错了吧
distance 这个方法的参数是Point3D 类型的,而(p2d1,p2d2)都是Point2D类型的,继承关系的问题吧
这个里面报错了吧
distance 这个方法的参数是Point3D 类型的,而(p2d1,p2d2)都是Point2D类型的,继承关系的问题吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询