老师布置了个作业,让判断空间中一个点是否在空间里的一个球内,两个类放在不同的包里。自己写了可是有错误查不出来。求高手帮忙写个,我参考下啊。或者指出下错误原因。点类:
package mos.point;import mos.ball.*;public class point1 {
double x;
double y;
double z;
point1(double a,double b,double c){
this.x=a;
this.y=b;
this.z=c; }
boolean isinball(ball b1){
boolean b=false;
if(b1.r>=this.getdistance(b1.center))
b=true;
return b;
}
double getdistance(point1 qx){
double l=0;
l=Math.sqrt((qx.x-this.x)*(qx.x-this.x)+(qx.y-this.y)*(qx.y-this.y)+(qx.z-this.z)*(qx.z-this.z));
return l;
}
public static void main(String agr[]){
point1 p1=new point1(2.3,4.3,3.2);
point1 center=new point1(3.2, 2.1, 3.4);
double r=4.5;
ball b1=new ball(center,r);
boolean inner=p1.isinball(b1);
if(inner){
System.out.println("点在球内");
}
else{
System.out.println("点不在球内");
}
}
球类:
package mos.ball;
import mos.point.*;
public class ball {
point1 center;double radius;
ball(){}
public ball(point1 center,double  r){
this.center=center;
this.radius=r;
}}
谢谢啦

解决方案 »

  1.   

    java命名规范你好好看下,类名首字母大写,方面里面的单词要xxPxx的形式对应的包路径改成你自己的,然后import你自己的路径就行了public class Point1 {
        double x;
        double y;
        double z;
        Point1(double a,double b,double c){
            this.x=a;
            this.y=b;
            this.z=c;    }
        boolean isInBall(Ball b1){
            boolean b=false;
            if(b1.radius>=this.getDistance(b1.center))
                b=true;
            return b;
        }
        double getDistance(Point1 qx){
            double l=0;
            l=Math.sqrt((qx.x-this.x)*(qx.x-this.x)+(qx.y-this.y)*(qx.y-this.y)+(qx.z-this.z)*(qx.z-this.z));
            return l;
        }
        public static void main(String agr[]){
            Point1 p1=new Point1(2.3,4.3,3.2);
            Point1 center=new Point1(3.2, 2.1, 3.4);
            double r=4.5;
            Ball b1=new Ball(center,r);
            boolean inner=p1.isInBall(b1);
            if(inner){
                System.out.println("点在球内");
            }
            else{
                System.out.println("点不在球内");
            }
        }
    }
    public class Ball {
        Point1 center;double radius;
        Ball(){}
        public Ball(Point1 center,double r){
            this.center=center;
            this.radius=r;
        }}